<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Daniel Sanche on Medium]]></title>
        <description><![CDATA[Stories by Daniel Sanche on Medium]]></description>
        <link>https://medium.com/@sanche?source=rss-b850cff30f35------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Opza8r2f-Oesq5RVrhLOwQ.png</url>
            <title>Stories by Daniel Sanche on Medium</title>
            <link>https://medium.com/@sanche?source=rss-b850cff30f35------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 18:04:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanche/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Introducing Google Cloud Logging Python v3.0.0]]></title>
            <link>https://medium.com/google-cloud/introducing-google-cloud-logging-python-v3-0-0-4c548663bab4?source=rss-b850cff30f35------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c548663bab4</guid>
            <category><![CDATA[gcp-app-dev]]></category>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Daniel Sanche]]></dc:creator>
            <pubDate>Wed, 02 Feb 2022 21:56:14 GMT</pubDate>
            <atom:updated>2022-02-03T02:43:22.683Z</atom:updated>
            <content:encoded><![CDATA[<h4>Manage your app’s Python logs and related metadata using Google Cloud</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/0*CaMup_vM-C9PnGfe" /></figure><p>We’re excited to announce the release of a major update to the Google Cloud Python logging library!</p><p>v3.0.0 makes it even easier for Python developers to send and read logs from Google Cloud, providing real-time insight into what is happening in your application. If you’re a Python developer working with Google Cloud, now is a great time to try out Cloud Logging!</p><p>If you&#39;re unfamiliar with the <a href="https://pypi.org/project/google-cloud-logging/">google-cloud-logging</a> library, getting started is simple. First, download the library using <a href="https://www.google.com/search?q=pip&amp;oq=pip&amp;aqs=chrome..69i57j35i39j0i67l3j69i60j69i65j69i60.1209j0j1&amp;sourceid=chrome&amp;ie=UTF-8">pip</a>:</p><pre>$ pip install &quot;google-cloud-logging&gt;=3.0.0&quot;</pre><p>Now, you can set up the client library to work with <a href="https://docs.python.org/3/howto/logging.html">Python’s built-in `logging` library</a>. Doing this will make it so that all your standard Python log statements will start sending data to Google Cloud:</p><pre># set up the Google Cloud Logging python client library<br>import google.cloud.logging<br>client = google.cloud.logging.Client()<br>client.setup_logging()</pre><pre># use Python’s standard logging library to send logs to GCP<br>import logging<br>logging.warning(“Hello World”)</pre><p>We recommend <a href="https://googleapis.dev/python/logging/latest/std-lib-integration.html">using the standard Python logging interface</a> for log creation, as demonstrated above. However, if you need access to other <a href="https://cloud.google.com/logging">Google Cloud Logging features</a> (reading logs, managing <a href="https://cloud.google.com/logging/docs/export/configure_export_v2">log sinks</a>, etc), you can <a href="https://googleapis.dev/python/logging/latest/direct-lib-usage.html">use google.cloud.logging directly</a>:</p><pre>import google.cloud.logging<br>client = google.cloud.logging.Client()<br>logger = client.logger(name=&quot;log_id&quot;)</pre><pre># read logs from GCP<br>client.list_entries(max_size=5)</pre><pre># write log to GCP<br>logger.log(&quot;hello world&quot;, resource={&quot;type&quot;:&quot;global&quot;, &quot;labels&quot;:{}})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NrBcBgzbFIfDKyYbw3Xf3Q.png" /></figure><p>Here are some of the main features of the <a href="https://github.com/googleapis/python-logging/blob/eac5e2db83f83b24962524fd9e0d7afa09e2785b/UPGRADING.md">new release</a>:</p><p><strong>Support More Cloud Environments</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/0*Ga8vwGp1V0JoN1xj" /></figure><p>Previous versions of google-cloud-logging supported only <a href="https://cloud.google.com/appengine">App Engine</a> and <a href="https://cloud.google.com/kubernetes-engine">Kubernetes Engine</a>. Users reported that the library would occasionally drop logs on serverless environments like Cloud Run and Cloud Functions. This was because the library would send logs in batches over the network. When serverless environments spin down, unsent batches could be lost.</p><p>v3.0.0 fixes this issue by making use of GCP’s built in <a href="https://cloud.google.com/logging/docs/structured-logging">structured JSON logging feature</a> (GKE, Cloud Run, or Cloud Functions). If the library detects it is running on an environment that supports structured logging, it will automatically make use of the new <a href="https://googleapis.dev/python/logging/latest/handlers-structured-log.html">StructuredLogHandler</a>, which writes logs as JSON strings printed to standard out. Google Cloud’s built-in agents will then parse the logs and deliver them to Cloud Logging, even if the code that produced the logs has spun down.</p><p>Structured Logging is more reliable on serverless environments, and it allows us to support all major GCP compute environments in v3.0.0. Still, if you would prefer to send logs over the network as before, you can manually set up the library with a <a href="https://googleapis.dev/python/logging/latest/handlers-cloud-logging.html">CloudLoggingHandler</a> instance:</p><pre>from google.cloud.logging.handlers import CloudLoggingHandler<br>from google.cloud.logging_v2.handlers import setup_logging</pre><pre># explicitly set up a CloudLoggingHandler to send logs over the network</pre><pre>handler = CloudLoggingHandler(client)<br>setup_logging(handler)</pre><pre>import logging<br>logging.warning(“Hello World”)</pre><p><strong>Metadata Auto-detection</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*rt-VSlMYhRIk_Srb0Jesvg.png" /></figure><p>When you troubleshoot your application, it can be useful to have as much information about the environment as possible captured in your application logs. google-cloud-logging attempts to help in this process by detecting and attaching metadata about your environment to each log message. The following fields are currently supported:</p><ul><li><a href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/MonitoredResource">resource</a>: The Google Cloud resource the log originated from<br> – For example, Functions, GKE, or Cloud Run</li><li><a href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest">httpRequest</a>: Information about an HTTP request in the log’s context <br> – Flask and Django are currently supported</li><li><a href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation">sourceLocation</a>: File, line, and function names</li><li><a href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry">trace</a>, <a href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry">spanId</a>, and <a href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry">traceSampled</a>: <a href="https://cloud.google.com/trace">Cloud Trace</a> metadata<br> – Supports <a href="https://cloud.google.com/trace/docs/setup#force-trace">X-Cloud-Trace-Context</a> and <a href="https://www.w3.org/TR/trace-context/#traceparent-header">w3c transparent</a> trace formats</li></ul><p>The library will make an attempt to populate this data whenever possible, but any of these fields can also be explicitly set by developers using the library:</p><pre>logging.info(&quot;hello&quot;, extra={<br>    &quot;labels&quot;: {&quot;foo&quot;: &quot;bar&quot;},<br>    &quot;http_request&quot;: {&quot;requestUrl&quot;: &quot;localhost&quot;},<br>    &quot;trace&quot;: &quot;01234&quot;<br>})</pre><h4><strong>JSON Support in Standard Library Integration</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*OA4S9WkQswXSgc6x3Krv8Q.png" /></figure><p>Google Cloud Logging supports both <a href="https://cloud.google.com/logging/docs/structured-logging">string and JSON payloads</a> for LogEntries, but up until now, the <a href="https://googleapis.dev/python/logging/latest/std-lib-integration.html">Python standard library integration</a> could only send logs with string payloads.</p><p>In `google-cloud-logging` v3.0.0, you can log JSON data in two ways:</p><ol><li>Log a JSON-parsable string:</li></ol><pre>import logging<br>import json</pre><pre>data_dict = {&quot;hello&quot;: &quot;world&quot;}<br>logging.info(json.dumps(data_dict))</pre><ol><li>Pass a `json_fields` dictionary using Python logging’s `extra` argument:</li></ol><pre>import logging</pre><pre>data_dict = {&quot;hello&quot;: &quot;world&quot;}<br>logging.info(&quot;message field&quot;, extra={&quot;json_fields&quot;: data_dict})</pre><h4>Next Steps</h4><ul><li>For more information on the latest release, check out the full <a href="https://googleapis.dev/python/logging/latest/UPGRADING.html">v3.0.0 Migration Guide</a></li><li>For developer documentation, see the <a href="https://googleapis.dev/python/logging/latest/index.html">google-cloud-logging user guide</a></li><li>If you have any feedback about the latest release, or would like to make any contributions, feel free to open issues on <a href="https://github.com/googleapis/python-logging">our GitHub repo</a></li><li>If you want to learn best practices of instrumenting your code for observability and running workloads reliably on GCP, try <a href="https://cloud-ops-sandbox.dev/">Cloud Ops Sandbox</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c548663bab4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/introducing-google-cloud-logging-python-v3-0-0-4c548663bab4">Introducing Google Cloud Logging Python v3.0.0</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes 120: Networking Basics]]></title>
            <link>https://medium.com/google-cloud/kubernetes-120-networking-basics-3b903f13093a?source=rss-b850cff30f35------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b903f13093a</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Daniel Sanche]]></dc:creator>
            <pubDate>Mon, 20 Aug 2018 20:48:32 GMT</pubDate>
            <atom:updated>2020-05-08T21:02:12.643Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve read <a href="https://medium.com/google-cloud/kubernetes-110-your-first-deployment-bf123c1d3f8">the previous article in this series,</a> you should now have a Gitea deployment successfully running on your cluster. The next step is to make it accessible through a web browser. This post will go over some basic Kubernetes networking topics, and in the process, make our Gitea container accessible over the public internet</p><h4>Opening Container Ports</h4><p>By default, pods are essentially isolated from the rest of the world. In order to route traffic to our application, we need to open the set of ports we plan to use for the container.</p><p>The software inside our Gitea container was designed to listen on port 3000 for HTTP requests, and 22 for SSH connections (to clone repositories). Let’s open up these ports in our container through the YAML file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2f8bd49f50a5d5887366eadff05d318/href">https://medium.com/media/b2f8bd49f50a5d5887366eadff05d318/href</a></iframe><p>Apply the updated file to the cluster:</p><pre>$ kubectl apply -f gitea.yaml</pre><p>Now, we should then be able to run kubectl describe deployment to see our newly opened ports listed in the deployment summary. Our pod should have ports 3000 and 22 open for connections.</p><pre>$ kubectl describe deployment | grep Ports<br>    Ports:        3000/TCP, 22/TCP</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SmTu4HGwrjOAV2AztQd1xQ.png" /><figcaption>Ports 3000 and 22 are now open on the container itself, but aren’t yet exposed to the open internet</figcaption></figure><h4>Debugging with Port Forward</h4><p>The ports on our container should now be open, but we still need a way to communicate with the pod in the cluster. For debugging purposes, we can attach to our pod using kubectl port-forward</p><pre># grab the name of your active pod<br>$ PODNAME=$(kubectl get pods --output=template \<br>     --template=&quot;{{with index .items 0}}{{.metadata.name}}{{end}}&quot;)</pre><pre># open a port-forward session to the pod<br>$ kubectl port-forward $PODNAME 3000:3000</pre><p>Now, kubectl will forward all connections on port 3000 on your local machine into the pod running in the cloud. If you open <a href="http://localhost:3000">http://localhost:3000 </a>in your web browser, you should be able to interact with the server as though it were running locally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0dK29wdVMg2Smn2ghenrhA.png" /><figcaption><em>“kubectl port-forward” </em>creates a temporary direct connection between an individual pod and your localhost</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nxNXFU_bKtQu-xijlVGAeA.png" /><figcaption>Connecting to <a href="http://localhost:3000">http://localhost:3000</a> should present you with the Gitea sign up page</figcaption></figure><h4>Creating an External LoadBalancer</h4><p>Now that we know our pod is working, lets make it accessible to the public internet. For this, we need to add a new Kubernetes resource that will provision a public public IP address and route incoming requests to our pod. This can be accomplished using a Kubernetes resource called a Service. There are a <a href="https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0">few different types of Services we could use</a>, but for our use case we will use a LoadBalancer.<a href="#7ab2">¹</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70fb2d27d84f5c5401a7cf4e58da25c7/href">https://medium.com/media/70fb2d27d84f5c5401a7cf4e58da25c7/href</a></iframe><p>Like the Deployment, the Service makes use of a selector (lines 29–30). This selector tells the LoadBalancer which pods to route traffic to. When the LoadBalancer receives requests, it will intelligently distribute the load to all pods that match the selector. In our case, load balancing is easy because we have just one pod.</p><p>The ports managed by the LoadBalancer are defined in lines 31–39. Along with a unique name and the protocol type (TCP/UDP), you must also define “port” and “targetPort”. These two fields define a mapping from ports on the external IP (port) to the ports used by the container (targetPort).<a href="#6a2a">²</a> On lines 33 and 34, we are saying that the LoadBalancer will listen to requests on port 80 (the default port your web browser uses to view websites), and pass the request to port 3000 on our pod.</p><p>Once again, we need to apply our updates to the cluster</p><pre>$ kubectl apply -f gitea.yaml</pre><p>After waiting a couple minutes for your changes to propagate, check on your service</p><pre>$ kubectl get service</pre><pre>NAME            TYPE           CLUSTER-IP     EXTERNAL_IP    AGE<br>gitea-service   LoadBalancer   10.27.240.34   35.192.x.x     2m</pre><p>After a couple minutes, you should see an external IP automatically added to your service. Entering this IP into your web browser will allow you to interact with the web server hosted by your pod.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*achzuYXYoyAtfsSo2wx7XA.png" /><figcaption>The new LoadBalancer exposes an external IP address. Incoming requests on port 80 will be routed to port 3000 on the Gitea pod. The Gitea sign up page should now be accessible over the open internet.</figcaption></figure><h4>Inter-Pod Communication: ClusterIP Service</h4><p>If you try running through the Gitea sign-up page, you’ll see there’s still something missing: Gitea requires a database to function. To solve this, we could either add a MySQL container into the Gitea pod as a <a href="https://www.voxxed.com/2015/01/use-container-sidecar-microservices/">side-car</a>, or we can create a new pod solely for MySQL.<a href="#b5ad">³</a> Both approaches may have their benefits and trade-offs, depending on your requirements. For the purposes of this tutorial, we will create a new pod.</p><p>Let’s start a new YAML file called <em>mysql.yaml</em> to manage the database:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3e6d26fd0d8a3f82ec2ab8221f4794a/href">https://medium.com/media/f3e6d26fd0d8a3f82ec2ab8221f4794a/href</a></iframe><p>Most of this should look familiar. Once again, we are declaring a Deployment to manage our single pod, and we are managing network connections through a Service. In this case, the service is of type “ClusterIP”; this simply means that the IP is exposed only within the cluster, rather than externally like through the LoadBalancer we made for the Gitea service.</p><p>Apply this new YAML file to the cluster</p><pre>$ kubectl apply -f mysql.yaml</pre><p>You should now see a new pod, deployment, and service added to your cluster</p><pre>$ kubectl get pods<br>NAME        READY     STATUS    RESTARTS   AGE<br>gitea-pod   1/1       Running   0          9m<br>mysql-pod   1/1       Running   0          9s</pre><pre>$ kubectl get deployments<br>NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE<br>gitea-deployment   1         1         1            1           11m<br>mysql-deployment   1         1         1            1           5m</pre><pre>$ kubectl get services<br>NAME            TYPE           CLUSTER-IP     EXTERNAL_IP    AGE<br>gitea-service   LoadBalancer   10.27.240.34   35.192.x.x  2m<br>mysql-service   ClusterIP      10.27.254.69   &lt;none&gt;         6m</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTdLPGP2x40zfYvZ_-VvcA.png" /><figcaption>MySQL is now deployed as a separate pod within the cluster. Its ClusterIP service can be accessed by the Gitea pod within the cluster, but it is not exposed over the public internet</figcaption></figure><p>The ClusterIP Service will automatically generate an internal IP address for us, listed in the console output as “CLUSTER-IP”. Any container within the cluster can access our MySQL pod using this address. Using these internal IP addresses directly is a bad practice, however. Instead, Kubernetes has an even easier way to access our new service: we can simply type “mysql-service” in the address field. This is possible due to a built-in pod called <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/">“kube-dns”</a>, which manages internal DNS resolution for all services.<a href="#c3e8">⁴</a> In this way, you can ignore ephemeral internal IP addresses, and instead use static, human readable service names.</p><p>To allow Gitea to communicate with the MySQL pod, simply write the name and port of the service in the “host” field of the web UI. If everything is working as expected, you should see an “access denied” error. This means our pods can successfully communicate, but they need more configuration to successfully authenticate. Stay tuned for the next post to learn how.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MiZn3YSfPHCVVwymcWRRNw.png" /></figure><h4>What’s Next</h4><p>This post went over some of the basics of Kubernetes Networking, including container ports, port forwarding, LoadBalancer and ClusterIP services, and kube-dns. Of course, networking is a giant topic, so much was left unsaid. If you want a lower-level explanation of how networking is implemented in Kubernetes, check out <a href="https://medium.com/google-cloud/understanding-kubernetes-networking-pods-7117dd28727">this series</a>. If you’re interested in controlling which pods can communicate in your cluster, you should look into <a href="https://github.com/ahmetb/kubernetes-network-policy-recipes">Network Policies.</a> If you want greater control over how services communicate with each other, look into service mesh offerings like <a href="https://istio.io/">Istio</a>.</p><p>As always, follow me here on Medium and on <a href="https://twitter.com/DanSanche21">Twitter (@DanSanche21)</a> for notifications when new articles are posted.</p><p>Footnotes</p><ol><li><a href="#fec2">^</a> LoadBalancers work great on cloud services like GCP, but if you are running a local cluster on <a href="https://blog.docker.com/2018/01/docker-mac-kubernetes/">Docker</a> or <a href="https://kubernetes.io/docs/setup/minikube/">Minikube</a>, you will likely need to use a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport">NodePort service</a> instead</li><li><a href="#8ce7">^</a> The external-facing port can be set to anything, but keep in mind that <a href="https://cloud.google.com/vpc/docs/firewalls">firewall rules may need to be set</a> on GKE if you want to access use something non-standard</li><li><a href="#5622">^</a> MySQL is used here because that’s what Gitea was designed to expect. MySQL is a legacy service that wasn’t built with Kubernetes in mind. If you are designing an application from scratch, there are likely other storage solutions that would be a better fit.</li><li><a href="#09fd">^</a> Kubernetes manages a number of hidden pods and services like this one. to see them, run kubectl get pods --namespace=kube-system</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b903f13093a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/kubernetes-120-networking-basics-3b903f13093a">Kubernetes 120: Networking Basics</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes 110: Your First Deployment]]></title>
            <link>https://medium.com/google-cloud/kubernetes-110-your-first-deployment-bf123c1d3f8?source=rss-b850cff30f35------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf123c1d3f8</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gitea]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[self-hosted]]></category>
            <dc:creator><![CDATA[Daniel Sanche]]></dc:creator>
            <pubDate>Thu, 19 Apr 2018 19:57:44 GMT</pubDate>
            <atom:updated>2020-05-08T20:58:32.153Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve <a href="https://medium.com/google-cloud/kubernetes-101-pods-nodes-containers-and-clusters-c1509e409e16">read my introduction to Kubernetes</a>, you should have a good foundational understanding of the basic pieces that make up Kubernetes. If you’re anything like me, however, you won’t fully understand a concept until you get hands on with it. This article is the first in a series that will go through the process of actually deploying a service to the cloud. Specifically, this tutorial will go over how to deploy Gitea, an open-source git hosting service, using Google Kubernetes Engine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bxty1VICQ5czvcGymLAhaA.png" /></figure><p>There’s nothing too special about Gitea specifically, but going through the process of deploying an arbitrary open source application to the cloud will give us some practical hands-on experience with using Kubernetes. Plus, at the end you will be left with a great self-hosted service you can use to host your future projects!</p><h3>Setting Up a Cluster</h3><h4>kubectl and gcloud</h4><p>The most important tool you use when setting up a Kubernetes environment is the <em>kubectl</em> command. This command allows you to interact with the Kubernetes API. It is used to create, update, and delete Kubernetes resources like pods, deployments, and load balancers.</p><p>There is a catch, however: <em>kubectl</em> can’t be used to directly provision the nodes or clusters your pods are run on. This is because Kubernetes was designed to be platform agnostic. Kubernetes doesn’t know or care where it is running, so there is no built in way for it to communicate with your chosen cloud provider to rent nodes on your behalf. Because we are using Google Kubernetes Engine for this tutorial, we will need to use the <em>gcloud</em> command for these tasks.</p><p>In brief, <em>gcloud</em> is used to provision the resources listed under “Hardware” on <a href="https://medium.com/google-cloud/kubernetes-101-pods-nodes-containers-and-clusters-c1509e409e16">my Kubernetes 101 post</a>, and <em>kubectl</em> is used to manage the resources listed under “Software”</p><p>This tutorial assumes you already have <em>kubectl</em> and <em>gcloud</em> installed on your system. If you’re starting completely fresh, you will first want to check out the first part of the <a href="https://cloud.google.com/kubernetes-engine/docs/quickstart">Google Kubernetes Engine Quickstart</a> to sign up for a GCP account, set up a project, enable billing, and install the command line tools.</p><p>Once you have your environment ready to go, you can create a cluster by running the following commands:</p><pre># create the cluster<br># by default, 3 standard nodes are created for our cluster<br>gcloud container clusters create my-cluster --zone us-west1-a</pre><pre># get the credentials so we can manage it locally through kubectl<br># creating a cluster can take a few minutes to complete<br>gcloud container clusters get-credentials my-cluster \<br>     --zone us-west1-a</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7GurIVeqjKYDigegfXE3oA.png" /><figcaption>We now have a provisioned cluster made up of three n1-standard1 nodes</figcaption></figure><p>Along with the<em> gcloud </em>command, you can manage your resources through the Google Cloud Console page. After running the previous commands, you should see your cluster appear <a href="https://console.cloud.google.com/kubernetes">under the GKE section</a>. You should also see a list of the VMs provisioned as your nodes <a href="https://console.cloud.google.com/compute">under the GCE section</a>. Note that although the GCE UI allows you to delete the VMs from this page, they are being managed by your cluster, which will re-create them when it notices they are missing. When you are finished with this tutorial and want to permanently remove the VMs, you can remove everything at once by deleting the cluster itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhS4icedu0sFKHXW6c4v1w.png" /></figure><h3>Deploying An App</h3><h4>YAML: Declarative Infrastructure</h4><p>Now that our cluster is live, it’s time to put it to work. There are two ways to add resources to Kubernetes: interactively through the command line using kubectl add, and declaratively, by defining resources in <a href="https://docs.ansible.com/ansible/latest/YAMLSyntax.html">YAML</a> files<a href="#34aa">¹</a>.</p><p>While interactive deployment with kubectl add is great for experimenting, YAML is the way to go when you want to build something maintainable. By writing all of your Kubernetes resources into YAML files, you can record the entire state of your cluster in a set of easily maintainable files, which can be version-controlled and managed like any other part of your system. In this way, all the instructions needed to host your service can be saved right alongside the code itself.</p><h4>Adding a Pod</h4><p>To show a basic example of what a Kubernetes YAML file looks like, let’s add a pod to our cluster. Create a new file called gitea.yaml and fill it with the following text:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db021d40a242ccc5238fdde80d5bcb7f/href">https://medium.com/media/db021d40a242ccc5238fdde80d5bcb7f/href</a></iframe><p>This pod is fairly basic. Line 2 declares that the type of resource we are creating is a pod; line 1 says that this resource is defined in v1 of the Kubernetes API. Lines 3–8 describe the properties of our pod. In this case, the pod is unoriginally named “gitea-pod”, and it contains a single container we’re calling “gitea-container”.</p><p>Line 8 is the most interesting part. This line defines which container image we want to run; in this case, the image tagged 1.4 in the<em> gitea/gitea</em> repository. Kubernetes will tell the built-in container runtime to find the requested container image, and pull it down into the pod. Because the default container runtime is Docker, it will find the gitea repository hosted on Dockerhub, and pull down the requested image.</p><p>Now that we have the YAML written out, we apply it to our cluster:</p><pre>kubectl apply -f gitea.yaml</pre><p>This command will cause Kubernetes to read our YAML file, and update any resources in our cluster accordingly. To see the newly created pod in action, you can run kubectl get pods. You should see the pod running.</p><pre>$ kubectl get pods</pre><pre>NAME        READY     STATUS    RESTARTS   AGE<br>gitea-pod   1/1       Running   0          9m</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yfjysGL85QF6qoO7-bYXQ.png" /><figcaption>Gitea is now running in a pod the cluster</figcaption></figure><p>If you want even more information, you can view the standard output of the container with the following command:</p><pre>$ kubectl logs -f gitea-pod</pre><pre>Generating /data/ssh/ssh_host_ed25519_key...<br>Feb 13 21:22:00 syslogd started: BusyBox v1.27.2<br>Generating /data/ssh/ssh_host_rsa_key...<br>Generating /data/ssh/ssh_host_dsa_key...<br>Generating /data/ssh/ssh_host_ecdsa_key...<br>/etc/ssh/sshd_config line 32: Deprecated option UsePrivilegeSeparation<br>Feb 13 21:22:01 sshd[12]: Server listening on :: port 22.<br>Feb 13 21:22:01 sshd[12]: Server listening on 0.0.0.0 port 22.<br>2018/02/13 21:22:01 [T] AppPath: /app/gitea/gitea<br>2018/02/13 21:22:01 [T] AppWorkPath: /app/gitea<br>2018/02/13 21:22:01 [T] Custom path: /data/gitea<br>2018/02/13 21:22:01 [T] Log path: /data/gitea/log<br>2018/02/13 21:22:01 [I] Gitea v1.4.0+rc1-1-gf61ef28 built with: bindata, sqlite<br>2018/02/13 21:22:01 [I] Log Mode: Console(Info)<br>2018/02/13 21:22:01 [I] XORM Log Mode: Console(Info)<br>2018/02/13 21:22:01 [I] Cache Service Enabled<br>2018/02/13 21:22:01 [I] Session Service Enabled<br>2018/02/13 21:22:01 [I] SQLite3 Supported<br>2018/02/13 21:22:01 [I] Run Mode: Development<br>2018/02/13 21:22:01 Serving [::]:3000 with pid 14<br>2018/02/13 21:22:01 [I] Listen: <a href="http://0.0.0.0:3000">http://0.0.0.0:3000</a></pre><p>As you can see, there is now a server running inside the container on our cluster! Unfortunately, we won’t be able to access it until we start opening up ingress channels (coming in a future post).</p><h4>Deployment</h4><p>As explained in <a href="https://medium.com/google-cloud/kubernetes-101-pods-nodes-containers-and-clusters-c1509e409e16">Kubernetes 101</a>, pods aren’t typically run directly in Kubernetes. Instead, we should define a deployment to manage our pods.</p><p>First, let’s delete the pod we already have running:</p><pre>kubectl delete -f gitea.yaml</pre><p>This command removes all resources defined in the YAML file from the cluster. We can now modify our YAML file to look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13925c5f4c2b7878c4a05c012e068d16/href">https://medium.com/media/13925c5f4c2b7878c4a05c012e068d16/href</a></iframe><p>This one looks a bit more complicated than the pod we made earlier. That’s because we are really defining two different objects here: the deployment itself (lines 1–9), and the template of the pod it is managing (lines 10–17).</p><p>Line 6 is the most important part of our deployment. It defines the number of copies of the pods we want running. In this example, we are only requesting one copy, because Gitea wasn’t designed with multiple pods in mind.<a href="#7bb9">²</a></p><p>There is one other new concept introduced here:<a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/"> labels and selectors</a>. Labels are simply user-defined key-value stores associated with Kubernetes resources. Selectors are used retrieve the resources that match a given label query. In this example, line 13 assigns the label “app=gitea” to all pods created by this deployment. Now, if the deployment ever needs to retrieve the list of all pods that it created (to make sure they are all healthy, for example) it will use the selector defined on lines 8–9. In this way, the deployment can always keep track of which pods it manages by searching for which ones have been assigned the “app=gitea” label.</p><p>For the most part, labels are user-defined. In the example above, “app” doesn’t mean anything special to Kubernetes, it is just a way that we may find useful to organize our system. Having said that, there are certain <a href="https://kubernetes.io/docs/reference/labels-annotations-taints/">labels that are automatically applied by Kubernetes</a>, containing information about the system.</p><p>Now that we have created our new YAML file, we can re-apply it to our cluster:</p><pre>kubectl apply -f gitea.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-cOLcYihvUwX4JXGoU16Ew.png" /><figcaption>Now, our pod is managed by a deployment</figcaption></figure><p>Now, if we run kubectl get pods we can now our new pods running, as specified in our deployment:</p><pre>$ kubectl get pods</pre><pre>NAME                               READY     STATUS     RESTARTS<br>gitea-deployment-8944989b8-5kmn2   0/1       Running    0<br></pre><p>We can see information about the deployment itself:</p><pre>$ kubectl get deployments</pre><pre>NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE<br>gitea-deployment   1         1         1            1           4m</pre><p>To test to make sure everything’s working, try deleting the pod with kubectl delete pod &lt;pod_name&gt;. You should quickly see a new one pop back in it’s place. That’s the magic of deployments!</p><p>You may have noticed that the new pod has weird, partially randomly generated name. That’s because pods are now created in bulk by the deployment, and are meant to be ephemeral. When wrapped in a deployment, pods should be <a href="http://cloudscaling.com/blog/cloud-computing/the-history-of-pets-vs-cattle/">thought of as cattle rather than pets.</a></p><h4>What’s Next</h4><p>We now have the Gitea software running in our cluster, but we have a way to go before we can interact with it through our web browser. The next post in the series, <a href="https://medium.com/@sanche/kubernetes-120-networking-basics-3b903f13093a">found here</a>, goes over basic networking features of Kubernetes. Future posts in this series will go over persistent storage, environment variables, and more. Make sure to follow me here on Medium and <a href="https://twitter.com/DanSanche21">Twitter (@DanSanche21)</a> for notifications when the new articles are posted.</p><p>Footnotes</p><ol><li><a href="#4d22">^</a> JSON works as well, but YAML is standard</li></ol><p>2. <a href="#450a">^</a> Gitea was designed to run locally on a single server. It assumes it lives on a single machine, and can read and write files to its directories without conflict. If we create multiple replicas of the Gitea pod and try to give them access to the same data, the replicas won’t know how to coordinate reads and writes, which can cause issues. Because Gitea wasn’t designed to properly coordinate multiple pods, it doesn’t make sense to have more than one replica in the cluster.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf123c1d3f8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/kubernetes-110-your-first-deployment-bf123c1d3f8">Kubernetes 110: Your First Deployment</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes 101: Pods, Nodes, Containers, and Clusters]]></title>
            <link>https://medium.com/google-cloud/kubernetes-101-pods-nodes-containers-and-clusters-c1509e409e16?source=rss-b850cff30f35------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1509e409e16</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Daniel Sanche]]></dc:creator>
            <pubDate>Tue, 02 Jan 2018 20:34:06 GMT</pubDate>
            <atom:updated>2018-05-14T00:50:43.680Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes is quickly becoming the new standard for deploying and managing software in the cloud. With all the power Kubernetes provides, however, comes a steep learning curve. As a newcomer, trying to parse the <a href="https://kubernetes.io/docs/concepts/">official documentation </a>can be overwhelming. There are many different pieces that make up the system, and it can be hard to tell which ones are relevant for your use case. This blog post will provide a simplified view of Kubernetes, but it will attempt to give a high-level overview of the most important components and how they fit together.</p><p>First, lets look at how hardware is represented</p><h3>Hardware</h3><h4>Nodes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyMd-QxYaOk_APwtuScsOg.png" /></figure><p>A <a href="https://kubernetes.io/docs/concepts/architecture/nodes/">node</a> is the smallest unit of computing hardware in Kubernetes. It is a representation of a single machine in your cluster. In most production systems, a node will likely be either a physical machine in a datacenter, or virtual machine hosted on a cloud provider like <a href="https://cloud.google.com/">Google Cloud Platform</a>. Don’t let conventions limit you, however; in theory, you can make a node out of <a href="https://twitter.com/jkrippy/status/932800484703862784">almost</a> <a href="https://blog.hypriot.com/post/setup-kubernetes-raspberry-pi-cluster/">anything</a>.</p><p>Thinking of a machine as a “node” allows us to insert a layer of abstraction. Now, instead of worrying about the unique characteristics of any individual machine, we can instead simply view each machine as a set of CPU and RAM resources that can be utilized. In this way, any machine can substitute any other machine in a Kubernetes cluster.</p><h4>The Cluster</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoMzLETQeN-c63x7xzSKPw.png" /></figure><p>Although working with individual nodes can be useful, it’s not the Kubernetes way. In general, you should think about the cluster as a whole, instead of worrying about the state of individual nodes.</p><p>In Kubernetes, nodes pool together their resources to form a more powerful machine. When you deploy programs onto the cluster, it intelligently handles distributing work to the individual nodes for you. If any nodes are added or removed, the cluster will shift around work as necessary. It shouldn’t matter to the program, or the programmer, which individual machines are actually running the code.</p><p>If this kind of hivemind-like system reminds you of the <a href="http://memory-alpha.wikia.com/wiki/Borg">Borg from Star Trek</a>, you’re not alone; “Borg” is the name for the <a href="http://blog.kubernetes.io/2015/04/borg-predecessor-to-kubernetes.html">internal Google project</a> Kubernetes was based on.</p><h4>Persistent Volumes</h4><p>Because programs running on your cluster aren’t guaranteed to run on a specific node, data can’t be saved to any arbitrary place in the file system. If a program tries to save data to a file for later, but is then relocated onto a new node, the file will no longer be where the program expects it to be. For this reason, the traditional local storage associated to each node is treated as a temporary cache to hold programs, but any data saved locally can not be expected to persist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kF57zE9a5YCzhILHdmuRvQ.png" /></figure><p>To store data permanently, Kubernetes uses <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/">Persistent Volumes</a>. While the CPU and RAM resources of all nodes are effectively pooled and managed by the cluster, persistent file storage is not. Instead, local or cloud drives can be attached to the cluster as a Persistent Volume. This can be thought of as plugging an external hard drive in to the cluster. Persistent Volumes provide a file system that can be mounted to the cluster, without being associated with any particular node.</p><h3>Software</h3><h4>Containers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ILinzzMdnD5oQ6Tu2bfBgQ.png" /></figure><p>Programs running on Kubernetes are packaged as <a href="https://www.docker.com/what-container">Linux containers</a>. Containers are a widely accepted standard, so there are already many <a href="https://hub.docker.com/explore/">pre-built images</a> that can be deployed on Kubernetes.</p><p>Containerization allows you to create self-contained Linux execution environments. Any program and all its dependencies can be bundled up into a single file and then shared on the internet. Anyone can download the container and deploy it on their infrastructure with very little setup required. Creating a container can be done programmatically, allowing powerful <a href="http://blog.sonatype.com/achieving-ci/cd-with-kubernetes">CI and CD</a> pipelines to be formed.</p><p>Multiple programs can be added into a single container, but you should limit yourself to one process per container if at all possible. It’s better to have many small containers than one large one. If each container has a tight focus, updates are easier to deploy and issues are easier to diagnose.</p><h4>Pods</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8OD0MgDNu3Csq0tGpS8Obg.png" /></figure><p>Unlike other systems you may have used in the past, Kubernetes doesn’t run containers directly; instead it wraps one or more containers into a higher-level structure called a <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/">pod</a>. Any containers in the same pod will share the same resources and local network. Containers can easily communicate with other containers in the same pod as though they were on the same machine while maintaining a degree of isolation from others.</p><p>Pods are used as the unit of replication in Kubernetes. If your application becomes too popular and a single pod instance can’t carry the load, Kubernetes can be configured to deploy new replicas of your pod to the cluster as necessary. Even when not under heavy load, it is standard to have multiple copies of a pod running at any time in a production system to allow load balancing and failure resistance.</p><p>Pods can hold multiple containers, but you should limit yourself when possible. Because pods are scaled up and down as a unit, all containers in a pod must scale together, regardless of their individual needs. This leads to wasted resources and an expensive bill. To resolve this, pods should remain as small as possible, typically holding only a main process and its tightly-coupled helper containers (these helper containers are typically referred to as “side-cars”).</p><h4>Deployments</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTAVk3glVD95hb-X3HiCKg.png" /></figure><p>Although pods are the basic unit of computation in Kubernetes, they are not typically directly launched on a cluster. Instead, pods are usually managed by one more layer of abstraction: the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">deployment</a>.</p><p>A deployment’s primary purpose is to declare how many replicas of a pod should be running at a time. When a deployment is added to the cluster, it will automatically spin up the requested number of pods, and then monitor them. If a pod dies, the deployment will automatically re-create it.</p><p>Using a deployment, you don’t have to deal with pods manually. You can just declare the desired state of the system, and it will be managed for you automatically.</p><h4>Ingress</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tBJ-_g4Mk5OkfzLEHrRsRw.png" /></figure><p>Using the concepts described above, you can create a cluster of nodes, and launch deployments of pods onto the cluster. There is one last problem to solve, however: allowing external traffic to your application.</p><p>By default, Kubernetes provides isolation between pods and the outside world. If you want to communicate with a service running in a pod, you have to open up a channel for communication. This is referred to as ingress.</p><p>There are multiple ways to add ingress to your cluster. The most common ways are by adding either an <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">Ingress</a> controller, or a <a href="https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/">LoadBalancer</a>. The exact tradeoffs between these two options are out of scope for this post, but you must be aware that ingress is something you need to handle before you can experiment with Kubernetes.</p><h4>What’s Next</h4><p>What’s described above is an oversimplified version of Kubernetes, but it should give you the basics you need to start experimenting. Now that you understand the pieces that make up the system, it’s time to use them to deploy a real app. Check out<a href="https://medium.com/@sanche/kubernetes-110-your-first-deployment-bf123c1d3f8"> Kubernetes 110: Your First Deployment</a> to get started.</p><p>To experiment with Kubernetes locally, <a href="https://kubernetes.io/docs/getting-started-guides/minikube/">Minikube</a> will create a virtual cluster on your personal hardware. If you’re ready to try out a cloud service ,<a href="https://cloud.google.com/kubernetes-engine/">Google Kubernetes Engine</a> has a collection of <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/">tutorials</a> to get you started.</p><p>If you are new to the world of containers and web infrastructure, I suggest reading up on the<a href="https://12factor.net/"> 12 Factor App methodology</a>. This describes some of the best practices to keep in mind when designing software to run in an environment like Kubernetes.</p><p>Finally, for more content like this, make sure to follow me here on Medium and on <a href="https://twitter.com/DanSanche21">Twitter (@DanSanche21).</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1509e409e16" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/kubernetes-101-pods-nodes-containers-and-clusters-c1509e409e16">Kubernetes 101: Pods, Nodes, Containers, and Clusters</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>