<?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 Stakater on Medium]]></title>
        <description><![CDATA[Stories by Stakater on Medium]]></description>
        <link>https://medium.com/@stakater?source=rss-d8b3ae5447e0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3JzYgn5_ypxuBnHTqJo1Gw.png</url>
            <title>Stories by Stakater on Medium</title>
            <link>https://medium.com/@stakater?source=rss-d8b3ae5447e0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 04:39:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stakater/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[Easy Kubernetes Development with Google Skaffold]]></title>
            <link>https://medium.com/stakater/easy-kubernetes-development-with-google-skaffold-cbddb7e40519?source=rss-d8b3ae5447e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbddb7e40519</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[skaffold]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Stakater]]></dc:creator>
            <pubDate>Fri, 03 May 2019 09:44:12 GMT</pubDate>
            <atom:updated>2019-05-03T09:54:20.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*ZMGYxvJqigG_HiDWXMPopQ.jpeg" /></figure><p>Skaffold is a command line tool from Google that brings automation to the deployment workflow of Kubernetes applications. This tool is tailored to provide developers with an experience of iteration and deployment which closely mirrors production. What this essentially means is that the developers will now be able to locally iterate on application source code without worrying about how it is updated in the later stages of validation and testing in the Kubernetes clusters.</p><p>Skaffold automates the traditional workflow and therefore handles building, pushing and deploying of applications running on Kubernetes clusters. Any directory with a Dockerfile can be deployed to Kubernetes cluster with this command line tool. What happens technically is that Skaffold builds the docker image locally, pushes it to a registry and deploys it using the skaffold CLI tool. For that reason, the work of developers becomes quite easy since they only need to launch Skaffold, run it in the background and develop their code while Skaffold updates the application continuously without the intervention of typing in any extra commands. At the same time, it can be employed when applications are being moved to production in the processes of continuous integration and continuous delivery due to its powerful tools. That is the inherent power that comes with Skaffold.</p><h3>Main features</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*wQ00NtXfM2Ivx39mRF-3Kg.jpeg" /></figure><p>Skaffold solves a problem for developers and to better understand how it works, let us look at the features that it offers:</p><ul><li>Skaffold is an automation tool and has the capability of detecting changes made on the source code while it runs and proceeds with the process of building, pushing and deploying automatically.</li><li>It supports multiple application components: Skaffold supports the workflows and tools that are already in your environment.</li><li>During implementation, Skaffold updates image tags in Kubernetes manifests which alleviates the developer from doing it manually. Thanks to the image tag management feature that comes with Skaffold.</li><li>Skaffold automatically detect changes in your source code and automatically build/push/deploy.</li><li>What is more interesting about Skaffold is that it has no server-side component. This reduces the configuration process and cluster overhead.</li></ul><h4>Where Skaffold saves the day</h4><ul><li>Deployment of applications on Kubernetes</li><li>Definition of build, push and deployment pipelines in the Continuous integration and Continuous delivery flow.</li><li>Quite useful in iterative builds in a loop of continuous build-deploy process.</li></ul><h4>Advantages of Skaffold</h4><p>Skaffold guarantees easy app deployment compared to the traditional way. This shortens the time of moving from Development to Production.</p><p>The architecture that Skaffold is built upon is a pluggable type of architecture. What this allows one to have is the freedom to pick the tools in the development workflow that work best. This provides flexibility and high usability compared to other tools such as Draft.</p><p>When compared to other tools, Skaffold has the source-code watching capability which triggers build and push automatically without further commands to facilitate it. This is one of the major reasons one should consider using Skaffold.</p><p>Skaffold saves invaluable time in deployment which can be spent on other activities to improve the economic status of an organization.</p><h3>Installing Skaffold</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*f5dkRxZT8pAdSWF1ioLEHg.jpeg" /></figure><p>For this setup, you need a working Kubernetes cluster or alternatively use Minikube. Check out our previous guide on how to install and configure minikube on your local machine. Once you have Kubernetes environment ready, proceed to install Skaffold.</p><p>Installation of Skaffold has the following prerequisites:</p><ul><li>Docker Engine</li><li>Docker image registry: Your docker client should be configured to push to an external docker image repository. If you’re using a minikube or Docker for Desktop cluster, you can skip this requirement.</li><li>kubectl — Kubernetes command-line tool</li></ul><p>Installing Skaffold is a straightforward process since the package is distributed as a binary file. You only need to download the package, place it under your <strong>$PATH</strong> and make it executable. You can use <em>wget</em> or <em>curl</em> to pull the binary file.</p><h4>Installing on Linux</h4><p>Download the package:</p><pre># wget https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64  -O /usr/local/bin/skaffold</pre><p>Make the file executable:</p><pre># chmod +x  /usr/local/bin/skaffold</pre><h4>Installing on macOS</h4><p>Download the package.</p><pre># wget https://storage.googleapis.com/skaffold/releases/latest/skaffold-darwin-amd64  -O /usr/local/bin/skaffold<br># chmod +x /usr/local/bin/skaffold</pre><p>Confirm that the directory with newly added skaffold package is in your PATH environment. You can confirm using:</p><pre># echo $PATH</pre><h3>Demo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*zlfk6qprxAxMr7RSYYHm-g.jpeg" /></figure><p>Now that you have everything you need to start playing with Skaffold, let’s work on a demo project to help you grasp all the concepts.</p><h4>Create Dockerfile</h4><p>Skaffold needs Dockerfile to be used for building Docker image.</p><pre>$ mkdir ~/skaffold-demo<br>$ cd ~/skaffold-demo<br>$ vim Dockerfile</pre><p>The contents of my Dockerfile are as below:</p><pre>FROM nginx<br><strong>COPY</strong> index.html /usr/share/nginx/html/<br><strong>WORKDIR</strong> /usr/share/nginx/html</pre><p>The content of index.html file:</p><pre>$ cat index.html<br>Hello world - Test Page 1</pre><p>This will pull official Docker image for Nginx, copies <em>index.html</em> file to Nginx default document root, and finally sets working directory to /usr/share/nginx/html.</p><h4>Create Kubernetes deployment</h4><p>Your next step is to create Kubernetes deployment yaml file. The contents of my file is:</p><pre>$ cat k8s-deployment.yaml<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>    name: hello-world<br>spec:<br>    selector:<br>      matchLabels:<br>        app: hello-world<br>    template:<br>      metadata:<br>        labels:<br>            app: hello-world<br>      spec:<br>        containers:<br>        - name: hello-world<br>          image: nginx-skaffold</pre><h4>Create Kubernetes Service</h4><pre>$ cat k8s-service.yaml <br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: hello-world<br>spec:<br>  selector:<br>    app: hello-world<br>  ports:<br>  - port: 8080<br>    protocol: TCP<br>    targetPort: 80<br>  type: LoadBalancer</pre><h4>Create Skaffold configuration</h4><p>The Skaffold configuration file is where the workflow is configured. In this file you define the tools you will be using and their configuration. Skaffold configuration file used in this demo has the following content.</p><pre>$ cat skaffold.yaml <br>apiVersion: skaffold/v1alpha2<br>kind: Config<br>build:<br>  artifacts:<br>  - imageName: nginx-skaffold<br>    workspace: .<br>  local: {}<br><br>deploy:<br>  kubectl:<br>    manifests:<br>      - k8s-*</pre><p>From the file definitions, it can be seen that Skaffold workflow has three main phases.</p><p>1. <strong>Build</strong></p><p>In the build phase, Skaffold builds an artifact using the tool of your choice. Artifacts are Docker images that you would like to deploy into your Kubernetes cluster when changes are made to them.</p><p>2. <strong>Push</strong></p><p>In the push phase, Skaffold ensures that your image is uploaded to the registry referenced in the image name. Before running Skaffold you should ensure that you are able to push to your configured image registry.</p><p>When using local Kubernetes clusters like Minikube or Docker for Desktop, the push is skipped because the image is already available locally.</p><p>3. <strong>Deploy</strong></p><p>The deploy step ensures that the most recent artifacts are running in the cluster. You can use different tools for deployment, for example kubectl or helm. Each deployment type has parameters that allow you to define how you want your app to be installed and updated.</p><p>You have to run skaffold dev command to initiate skaffold deployment on your local Kubernetes environment.</p><pre>$ skaffold dev</pre><p>You should receive an output like below:</p><pre>$  skaffold dev          <br>Starting build...<br>Found [minikube] context, using local docker daemon.<br>Sending build context to Docker daemon  8.704kBStep 1/4 : FROM nginx ---&gt; c5c4e8fa2cf7<br>Step 2/4 : COPY index.html /usr/share/nginx/html/index.html<br> ---&gt; Using cache<br> ---&gt; b2743e4ff68a<br>Step 3/4 : WORKDIR /usr/share/nginx/html<br> ---&gt; Using cache<br> ---&gt; 4ee8631f078b<br>Step 4/4 : EXPOSE 80<br> ---&gt; Using cache<br> ---&gt; 51a516564d41<br>Successfully built 51a516564d41<br>Successfully tagged 87de02f02ad14494edd89e60779062fd:latest<br>Successfully tagged nginx-skaffold:51a516564d41fc9a39d714abcba1464ee301c5feb9de6ab858bc047a74ad3a79<br>Build complete in 231.654336ms<br>Starting deploy...<br>Deploying k8s-deployment.yaml...<br>Deploying k8s-service.yaml...<br>Deploy complete in 685.787798ms<br>Watching for changes...</pre><p>To access your running service, you need to run:</p><pre>$ minikube service [service-name]</pre><p>In our example, this should be:</p><pre>$ minikube service hello-world</pre><p>This opens nginx page on your default browser and displays the content that was added to index.html file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MG2EcZs3XHJtDwlg" /></figure><p>Whenever you make any changes to the index.html file, Skaffold should update your deployed application continually:</p><pre>$ cat index.html<br><br>Hello world - Test Page 2</pre><p>Upon saving the changes, you should see Skaffold doing redeployment automatically</p><pre>Starting build...<br>Found [minikube] context, using local docker daemon.<br>Building [nginx-skaffold]...<br>Sending build context to Docker daemon  3.072kB<br>Step 1/3 : FROM nginx<br> ---&gt; 06144b287844<br>Step 2/3 : COPY index.html /usr/share/nginx/html/<br> ---&gt; fd751a98ac09<br>Step 3/3 : WORKDIR /usr/share/nginx/html<br> ---&gt; 0a4009d6de20<br>Successfully built 0a4009d6de20<br>Successfully tagged f15dd87578a0fb660a2e66cc3da0cf96:latest<br>WARN[1350] Using digest instead of git <strong>commit</strong>: Running [git rev-<strong>parse</strong> --short HEAD]: stdout , stderr: fatal: not a git repository (or any of the parent directories): .git<br>, err: <strong>exit</strong> <strong>status</strong> 128: <strong>exit</strong> <strong>status</strong> 128 <br><strong>Build</strong> <strong>complete</strong> <strong>in</strong> 1.012115486s<br><strong>Starting</strong> deploy...<br>deployment.apps/hello-world configured<br>service/hello-world unchanged<br>Deploy <strong>complete</strong> <strong>in</strong> 1.073736335s<br>Watching <strong>for</strong> changes...</pre><p>Reload the webpage to see new changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8ibWXglo1enEg55r" /></figure><h3>Conclusion</h3><p>Skaffold is a command line tool designed to facilitate continuous development of Kubernetes applications. By using Skaffold, it is easy to iterate on your application source code locally and later deploy to a remote or local Kubernetes clusters.</p><p>Leverage this tool to improve your productivity by ensuring you have quick automated deployments of Kubernetes applications. You can read more about Skaffold on its <a href="https://skaffold.dev/">website</a> or <a href="https://github.com/GoogleContainerTools/skaffold">Github repository</a></p><figure><a href="http://stakater.com/?utm_medium=blog&amp;utm_source=easy-kubernetes-development-with-google-skaffold-cbddb7e40519"><img alt="" src="https://cdn-images-1.medium.com/max/700/1*0FANFMBaw8Q8aLuPQJLOOA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbddb7e40519" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stakater/easy-kubernetes-development-with-google-skaffold-cbddb7e40519">Easy Kubernetes Development with Google Skaffold</a> was originally published in <a href="https://medium.com/stakater">Stakater</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating uptime monitoring on Kubernetes with UptimeRobot]]></title>
            <link>https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-uptimerobot-c167732981d5?source=rss-d8b3ae5447e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c167732981d5</guid>
            <category><![CDATA[uptime]]></category>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[uptime-robot]]></category>
            <dc:creator><![CDATA[Stakater]]></dc:creator>
            <pubDate>Mon, 24 Sep 2018 20:15:42 GMT</pubDate>
            <atom:updated>2018-10-04T05:41:39.072Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*yxJvJBrqiiKE8npH5ouPmg.png" /></figure><p>This is the third part of this current series of blogs. The previous two articles can be found <a href="https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-statuscake-dd203d2bac65">here</a> and <a href="https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-pingdom-6a40977f82e1">here</a>. In this article, we will be looking at another Uptime checker that can be used for monitoring liveness of our services, UptimeRobot.</p><p>Ingress Monitor Controller (IMC) is a Kubernetes controller designed to continuously watch ingresses created from deployed services in all namespaces , and automatically add or remove monitors on UptimeRobot. This removes the manual task of managing monitors lifecycle. Other monitors supported are Pingdom and StatusCake.</p><p>UptimeRobot is a free monitoring service founded in Jan 2010 with a Pro Plan. It monitors your websites every x seconds/minutes and sends you alerts whenever the sites are down. This is how UptimeRobot works behind the hood:</p><ul><li>It monitors website by asking for its headers and gets status codes like “<strong>200-ok</strong>”, “<strong>404-not found</strong>” every configured period of time.</li><li>It uses status codes from response, If the status code doesn’t match associated problem, then it is good.</li><li>If the status code is <strong>~400+</strong> and <strong>500+</strong>, it means the site is not loading as expected. To make sure the site is down, Uptime Robot makes several more checks in the next 30 seconds</li><li>If the site has been confirmed to be down, it sends an alert through the Alert Contacts associated with the Monitor</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*mZbEUWtUOwkcVToIzSQHcw.jpeg" /></figure><h3>Below are the interesting features of Uptime Robot</h3><ol><li><strong>Has Multiple check methods</strong> : Uptime Robot uses HTTP(s), ping, port and keywords to check website status. If you have a web service listening on non standard port, you’ll specify service port when adding a Monitor.</li><li><strong>Support many Alert Methods</strong>: Uptime Robot has support for SMS, Slack, email,Telegram, Twitter, HipChat, push and web-hooks alerting. A single monitor can have multiple alert contacts/methods.</li><li><strong>Uptime Robot has a very easy-to-use API</strong>: With Uptime Robot API, you can get the details of your monitors, logs, create/edit/delete monitors, alert contacts and maintenance windows. Responses are provided as XML, JSON or JSON-P.</li><li><strong>Advanced notifications: </strong>If you’re not interested with minor downtimes, you can Ignore them by setting “<em>alert once (or every x minutes) </em>if down for <em>y minutes</em>”</li><li><strong>Flexible Maintenance windows</strong>: You can easily define time periods that you don’t want the services to be monitored, e.g. when doing site maintenance.</li><li><strong>Verification from Multiple Locations</strong>: Uptime Robot Verifies downtime from multiple locations before final state of the service is reached.</li><li><strong>Website stats</strong>: From the dashboard you can view uptime, downtime and the response times of all your websites. This helps a lot when analyzing whether the service meets customer’s SLA.</li><li><strong>Access to Public status pages</strong>: This allows you to share the stats of your websites with your teammates and/or visitors</li></ol><p>These features are fit for monitoring Kubernetes Ingresses and Services with the help of Ingress Monitor Controller.</p><h3>Creating Uptimerobot Account</h3><p>In case you’re new to Uptimerobot and would like to signup for a new account, head over to signup page <a href="https://uptimerobot.com/signUp">https://uptimerobot.com/signUp</a>. There is a <strong>Free Plan which provides</strong>:</p><ul><li><strong>5 minutes monitoring intervals</strong></li><li><strong>Upto 50 monitors</strong></li><li><strong>2 months of logs</strong></li></ul><p>You can start with the free plan the upgrade later depending on your business requirements. Provide username, email address and the password for the new account.</p><p>IMC requires API credentials to connect to Uptimerobot to push updates about Kubernetes Services/Ingresses. Obtain your API credentials by navigating to <a href="https://uptimerobot.com/login">https://uptimerobot.com/login</a>. Login to the dashboard and go to <a href="https://uptimerobot.com/dashboard.php#mySettings">https://uptimerobot.com/dashboard.php#mySettings</a>, near the bottom of the page, there is a section <strong>API Settings &gt; Create the main API key.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rSZ-oJZgMswPSxKY" /></figure><p>Save your Main API key as we will use it later.</p><h3>Deploying Ingress to be monitored by IMC</h3><p>By default, Ingress Monitor controller will ignore ingress definitions without IMC annotation added, and they will not be monitored. All ingresses to be monitored needs to have annotation below:</p><pre><strong>monitor</strong>.stakater.com/enabled: “true”</pre><p>Here is a complete example of Nginx Ingress controller</p><pre>apiVersion: extensions/v1beta1<br>kind: Ingress<br>metadata:<br>  namespace: test-namespace<br>  name: app-ingress<br>  annotations:<br>    kubernetes.io/ingress.class: &quot;nginx&quot;<br>    monitor.stakater.com/enabled: &quot;true&quot;<br>spec:<br>  rules:<br>  - host: app.example.com<br>    http:<br>      paths:<br>      - path: /<br>        backend:<br>          serviceName: app-svc-1<br>          servicePort: 80</pre><p>Notice IMC annotation with <strong>true</strong> boolean under annotations. This will create an Ingress named <em>app-ingress</em> that serves from a service called<em> app-svc-1</em></p><h3>Deploying IMC to Kubernetes</h3><p>Once you have created your Ingresse(s) with correct annotation, you can proceed to deploy IMC into your cluster.</p><p>Below are the steps to deploy IMC to your Kubernetes cluster using Vanilla Manifests files.</p><p>First, clone IMC code from Github:</p><pre>$ git clone <a href="https://github.com/stakater/IngressMonitorController">https://github.com/stakater/IngressMonitorController</a></pre><p>Change to IngressMonitorController directory created from cloning.</p><pre>$ cd IngressMonitorController</pre><p>The vanilla IMC deployment manifests are located under <em>deployments/kubernetes/manifests.</em><strong> </strong>Change your working directory to this path.</p><pre>$ cd deployments/kubernetes/</pre><p>In this directory there is a main IMC yaml file called <em>ingressmonitorcontroller.yaml</em>, this is the file you’ll edit to make all changes before deployment.</p><pre>$ ls</pre><pre>README.md chart <strong>ingressmonitorcontroller.yaml</strong> manifests templates</pre><h4>Configure IMC for Uptimerobot Monitor</h4><p>Provide the correct namespace name by editing ingressmonitorcontroller.yaml.</p><pre><strong>namespace</strong>: dev</pre><p>Then Edit the data section of <em>ConfigMap</em> to provide Uptimerobot specific configurations</p><pre>data:<br>  config.yaml: |-<br>    providers:<br>    - name: UptimeRobot<br>      apiKey: your-api-key<br>      apiURL: https://api.uptimerobot.com/v2/<br>      username: uptimerobot-email-address<br>      password: uptimerobot-account-password<br>      alertContacts: some-alert-contacts<br>    enableMonitorDeletion: true<br>    monitorNameTemplate: &quot;{{.Namespace}}-{{.IngressName}}&quot;</pre><p>To create contact group on UptimeRobot, login and navigate to <strong>My Settings &gt; Alert Contacts &gt; Add Alert Contact</strong></p><p>Select Alert Contact type from:</p><ul><li>Email</li><li>SMS</li><li>Twitter</li><li>Web-Hook</li><li>3rd Party apps/services like HipChat, Slack, Telegram etc.</li></ul><p>It is possible to fetch alert contacts from CLI using curl and Uptimerobot REST API:</p><pre>$ curl -d “api_key=your_uptimerobot_api_key” -X POST <a href="https://api.uptimerobot.com/v2/getAlertContacts">https://api.uptimerobot.com/v2/getAlertContacts</a></pre><p>Copy values of <strong>id</strong> field of your alert contacts which you want to use for Ingress Monitor Controller. If you have more than one contact, you’ll need to append <strong>_0_0</strong> to and separate them by <strong>-. </strong>Let’s consider an example, suppose you have two contact groups with IDs <strong>4567 </strong>and <strong>4578. </strong>Value to be used on <strong>alertContacts:</strong> should look like below:</p><pre>4567_0_0–4578_0_0</pre><p>The <strong>enableMonitorDeletion</strong> option is used to safeguard to enable or disable monitor deletion upon ingress deletion. You may want to set it to <strong>false </strong>for environments that keeps resetting Ingress, but for same backend services.</p><p>When done making changes to the file, proceed to deploy IMC to Kubernetes using updated <strong>ingressmonitorcontroller</strong> file</p><pre>$ <strong>kubectl -n dev apply -f ingressmonitorcontroller.yaml</strong> <br>configmap/ingressmonitorcontroller created<br>serviceaccount/ingressmonitorcontroller configured<br>clusterrole.rbac.authorization.k8s.io/ingressmonitorcontroller-role configured<br>clusterrolebinding.rbac.authorization.k8s.io/ingressmonitorcontroller-role-binding configured<br>deployment.extensions/ingressmonitorcontroller created</pre><p>Confirm creation of IMC deployment and pod:</p><pre><strong>$ kubectl -n dev get deployments. | grep ingressm</strong><br>ingressmonitorcontroller 1 1 1 1 1m</pre><pre><strong>$ kubectl -n dev get pod | grep ingressm</strong></pre><pre>ingressmonitorcontroller-ffdb9567b-wcjt8 1/1 Running 0 2m</pre><p>Now that we have a running IMC pod, tail logs to see if there is any error:</p><pre>$ kubectl -n <strong>test</strong>-namespace logs ingressmonitorcontroller-ffdb9567b-wcjt8<br>2018/08/08 16:29:55 Warning: KUBERNETES_NAMESPACE is unset, will <strong>monitor</strong> ingresses <strong>in</strong> all namespaces.<br>2018/08/08 16:29:55 Reading YAML Configuration<br>2018/08/08 16:29:55 Starting Ingress <strong>Monitor</strong> controller<br>2018/08/08 16:29:56 <strong>Monitor</strong> Name: <strong>test</strong>-namespace-http-app-svc-ingress<br>2018/08/08 16:29:56 <strong>Monitor</strong> URL: <a href="http://test1.example.com/">http://test1.example.com/</a><br>2018/08/08 16:29:57 <strong>Monitor</strong> Added: <strong>test</strong>-namespace-http-app-svc-ingress</pre><p>We can confirm that the Ingress has been added to Uptimerobot for monitoring.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jQBYGDSGtZywIW8P" /></figure><p>When an Ingress is deleted, the monitor will be removed from UptimeRobot as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sVRtHJTQ4ZpoZiMl" /></figure><p>From the screenshot above, you can confirm that there is no Monitor since the one we added earlier has been removed. Visit <a href="https://github.com/stakater/IngressMonitorController">IMC Github page</a> to check the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*0FANFMBaw8Q8aLuPQJLOOA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c167732981d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-uptimerobot-c167732981d5">Automating uptime monitoring on Kubernetes with UptimeRobot</a> was originally published in <a href="https://medium.com/stakater">Stakater</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating uptime monitoring on Kubernetes with Pingdom]]></title>
            <link>https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-pingdom-6a40977f82e1?source=rss-d8b3ae5447e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a40977f82e1</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[pingdom]]></category>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[uptime-monitoring]]></category>
            <dc:creator><![CDATA[Stakater]]></dc:creator>
            <pubDate>Mon, 20 Aug 2018 19:26:32 GMT</pubDate>
            <atom:updated>2018-12-24T20:02:34.109Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="http://stakater.com/?utm_source=automating-uptime-monitoring-on-kubernetes-with-pingdom-6a40977f82e1&amp;utm_medium=blog"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKZ4GIxBnnkKhRr50_HqYA.png" /></a></figure><p>This is the second part of this current series of blogs. The <a href="https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-statuscake-dd203d2bac65">previous article</a> discusses automating monitoring for Statuscake. In this article, we will be looking at another Uptime checker that can be used for monitoring liveness of our services, Pingdom.</p><p><a href="https://www.pingdom.com/">Pingdom</a> is a managed, commercial single platform solution for monitoring the availability and performance of web applications and services. With over<strong> 60+</strong> probe servers worldwide, we can be confident that we will always get a true state of services being monitored.</p><h3>Pingdom features</h3><p>Below are features that Pingdom provides:</p><p><strong>Uptime Monitoring</strong>: Pingdom provides real-time monitoring for site availability from over 70 locations worldwide.</p><p><strong>Instant Alerts</strong>: Get instant notification via SMS, Slack or Email whenever the website goes down.</p><p><strong>Page Speed Monitoring</strong>: Examine and optimize the load time of the website using Page speed reports.</p><p><strong>Visitor Insights</strong>: Find out whether visitors are happy or frustrated with the website’s performance, and how it performs from a specific country or web browser.</p><p><strong>Transaction Monitoring Tools</strong>: Automated website interaction simulation to evaluate validity and performance of site flows.</p><p>Our key focus on using Pingdom for Kubernetes microservices monitoring is to get immediate alerts when an incident happen, and with relevant information needed to resolve an issue as quickly as possible. Service liveness monitoring is most commonly done through the HTTP protocol.</p><p>As you roll out production services leveraging Infrastructure based in containers and Kubernetes Orchestration engine, you’ll need a monitoring solution such as Pingdom for all services being deployed. Registering multiple services, and updating or deleting each which may need to be modified can be a pain when dealing with many multiples of services. The work of Ingress Monitor Controller (IMC) is to watch your Kubernetes Services/Ingresses and <strong>automatically</strong> create/update or delete monitors on Pingdom. So in this context we can think of Ingress Monitor Controller (IMC) is an “<em>automated monitoring agent</em>” for Pingdom. Once the state of the service is recorded on Pingdom, an alert can be triggered depending on the state value.</p><p>This helps to bridge the gap between real-time monitoring of Kubernetes services and manual addition/removal of uptime monitors on Pingdom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*RP0si72D-jrNkkmzzJ_5IA.png" /></figure><h3>Pingdom Account set up</h3><p>If you’re new to Pingdom and would like to create a test account, there is a 14 day trial. You can quickly sign up on <a href="https://www.pingdom.com/signup/">https://www.pingdom.com/signup/</a> for the Pingdom Starter package.</p><p>Once the sign up process is completed, Login to Pingdom Management dashboard to obtain your API credentials on <a href="https://my.pingdom.com/account/appkeys">https://my.pingdom.com/account/appkeys</a>. This is same as navigating to<strong> Integrations &gt; The Pingdom API &gt; Register Application</strong>. You’ll be asked to provide application name and Description. See below screenshot for visualization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61iCQ2Sg9KD0EpdsflNpWA.png" /></figure><p>When done, click “<strong>Register</strong>” button at the bottom to generate API credentials to be used on IMC setup. New Application Key should be generated with name provided. This will be your <strong>apiKey</strong> on IMC.</p><h3>Services on Kubernetes</h3><p>Let’s take a look at an example setup on Kubernetes with which we can use Pingdom for creating monitors and alerts for our service. We will start by creating a simple service deployment to be used in our test in the test namespace.</p><p>Create a test namespace using the command below:</p><pre>$ kubectl create <strong>namespace</strong> test-<strong>namespace</strong><br><strong>namespace</strong>/test-<strong>namespace</strong> created</pre><p>We will then deploy a test web application based on katacoda <a href="https://github.com/katacoda/golang-http-server">golang-http-server</a> to the namespace added above.</p><h4>Step 1: Start by creating a directory for deployments:</h4><pre>$ mkdir k8s-test<br>$ cd k8s-test</pre><h4>Step 2: Create a deployment configuration object:</h4><pre>$ <strong>vim deployment.yml<br></strong>apiVersion: extensions/v1beta1<br>kind: Deployment<br>metadata:<br>  name: http-app<br>spec:<br>  replicas: 2<br>  template:<br>    metadata:<br>      labels:<br>        app: http-app<br>    spec:<br>      containers:<br>      - name: http-app<br>        image: katacoda/docker-http-server:latest<br>        ports:<br>        - containerPort: 80</pre><p>To deploy, run the command:</p><pre>$ kubectl apply -f deployment.yml<br>deployment.extensions/http-app created</pre><p>Two pods should be created from the above command:</p><pre>$ kubectl -<strong>n</strong> <strong>test</strong>-namespace get pod | grep http-<strong>app</strong><br>http-<strong>app</strong>-97f76fcd8-mzv49       1/1       Running   0          3m<br>http-<strong>app</strong>-97f76fcd8-xkhj7       1/1       Running   0          3m</pre><p>When done with the deployment, then create a service:</p><pre>$ cat http-app-service.yml <br>apiVersion: v1<br>kind: Service<br>metadata:<br> name: http-app-svc<br> labels:<br> app: http-app<br>spec:<br> type: NodePort<br> ports:<br> — port: 80<br> nodePort: 30080<br> selector:<br> app: http-app</pre><p>Deploy it to Kubernetes by running below command:</p><pre>$ kubectl -n test-namespace apply -f http-app-service.yml<br>service/http-app-svc created<br>$ kubectl -n test-namespace get service | grep http-app-svc<br>http-app-svc NodePort 10.98.53.188 &lt;none&gt; 80:30080/TCP 28s</pre><p>Test service functionality using curl:</p><pre>$ curl 10.98.53.188<br>&lt;h1&gt;This request was processed by host: http-app-97f76fcd8-xkhj7&lt;/h1&gt;<br>$ curl 10.98.53.188<br>&lt;h1&gt;This request was processed by host: http-app-97f76fcd8-mzv49&lt;/h1&gt;</pre><p>You can confirm that we’re getting response from our two pods created earlier.</p><p>Step 3: Creating an Ingress resource</p><p>For a service on Kubernetes to be exposed to the external world, you need to deploy an Ingress. Ingress is a collection of rules and routing policies that govern how external users get access to Kubernetes internal services. For this guide, we are using <a href="https://github.com/kubernetes/ingress-nginx">Kubernetes Nginx Ingress</a>. Learn more about deploying and using Ingress on Kubernetes on <a href="http://kubernetes.io/docs/user-guide/ingress/">k8s.io</a></p><p>Once you have an Ingress deployed, proceed to create an ingress resource which has a definition of the service that the Ingress will serve from. Below is the resource definition:</p><pre>$ cat nginx-ingress.yml<br>apiVersion: extensions/v1beta1<br>kind: Ingress<br>metadata:<br> namespace: test-namespace<br> name: http-app-svc-ingress<br> annotations:<br>   kubernetes.io/ingress.class: &quot;nginx&quot;<br>   monitor.stakater.com/enabled: &quot;true&quot;<br>spec:<br> rules:<br> — host: service.example.com<br> http:<br> paths:<br> — path: /<br> backend:<br> serviceName: http-app-svc <br> servicePort: 80</pre><p>Replace<em> service.example.com</em> with your valid service domain/subdomain record.</p><p>You can then deploy it to Kubernetes cluster using the <em>kubectl apply</em> command:</p><pre>$ kubectl apply -f ingress.yml</pre><p>This ingress is linked to our service (<em>http-app-svc</em>) created earlier as the backend. Make sure you have <strong>monitor</strong>.stakater.com/enabled: “true” annotation for IMC to monitor it.</p><pre>$ kubectl -n test-namespace get ingresses.extensions <br>NAME HOSTS ADDRESS PORTS AGE<br>*.svc-ingress test.example.com 192.168.10.5 80 10s</pre><p>When Ingress is running, you can proceed to deploy IMC.</p><h3>How to Deploy Ingress Monitor Controller</h3><p>IMC watches Ingresses in the cluster for registering on Pingdom. IMC can monitor ingresses on all or specific namespaces. To deploy IMC in the cluster, we can follow these simple steps:</p><p>First download the manifest file from the repository</p><pre>$ wget <a href="https://raw.githubusercontent.com/stakater/IngressMonitorController/master/deployments/kubernetes/ingressmonitorcontroller.yaml">https://raw.githubusercontent.com/stakater/IngressMonitorController/master/deployments/kubernetes/ingressmonitorcontroller.yaml</a></pre><p>Edit the ingressmonitorcontroller.yaml file to specify correct namespace</p><pre>$ grep <strong>namespace</strong> ingressmonitorcontroller.yaml <br> <strong>namespace</strong>: test-<strong>namespace</strong></pre><p>Next we need to edit <strong>configmap</strong>.yaml data of the ConfigMap resource to specify configuration parameters for Pingdom under the <strong>data</strong> section.</p><p>Populate the data section with your Pingdom API credentials:</p><pre>data:<br> config.yaml: |-<br>   providers:<br>   — name: Pingdom<br>   apiKey: pingdom-api-key<br>   apiURL: <a href="https://api.pingdom.com/">https://api.pingdom.com/</a><br>   username: email-address<br>   Password: pingdom-account-password<br>   enableMonitorDeletion: true<br>   monitorNameTemplate: &quot;{{.Namespace}}-{{.IngressName}}&quot;</pre><p>Once you have made the changes, apply them to Kubernetes cluster by running:</p><pre>$ kubectl apply -f ingressmonitorcontroller.yaml -n test-namespace<br>serviceaccount/ingressmonitorcontroller created<br>configmap/ingressmonitorcontroller configured<br>deployment.extensions/ingressmonitorcontroller created<br>clusterrole.rbac.authorization.k8s.io/ingressmonitorcontroller-role created<br>clusterrolebinding.rbac.authorization.k8s.io/ingressmonitorcontroller-role-binding created</pre><p>Lastly ensure Deployment object is running as well.</p><pre>$ kubectl -n test-namespace get pods | grep ingressmonitorcontroller<br>ingressmonitorcontroller-84dccb865c-gdpvd 1/1 Running 0 10d</pre><p>Once the Ingress Monitor Controller is in running state, login to Pingdom Dashboard and confirm if uptime test for the ingress was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CRBMY9vNi0YhKZV3" /></figure><p>Under<strong> Reports &gt; Uptime</strong>, you can also see uptime reports, when did the server go down,e.t.c.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rgyQ1VUG-kSe8vUB" /></figure><p>Here is also a quick demonstrating of how Ingress Monitor Controller registers monitors on Pingdom for new Ingresses:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FP5fTEJsygPg%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DP5fTEJsygPg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FP5fTEJsygPg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a04004eadaa8747f9cf91d95c422701/href">https://medium.com/media/9a04004eadaa8747f9cf91d95c422701/href</a></iframe><h3>Conclusion</h3><p>Pingdom offers some rich features for website monitoring, including liveness checking and alerting. And when multiple services need to be monitored on Kubernetes, Ingress Monitor Controller (IMC) can be used for easily automating monitors to Pingdom. When an ingress is created or deleted, you don’t need to manually add or remove the monitor on Pingdom, IMC does the job for you automatically.</p><figure><a href="http://stakater.com/?utm_source=automating-uptime-monitoring-on-kubernetes-with-pingdom-6a40977f82e1&amp;utm_medium=blog"><img alt="" src="https://cdn-images-1.medium.com/max/700/1*0FANFMBaw8Q8aLuPQJLOOA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a40977f82e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-pingdom-6a40977f82e1">Automating uptime monitoring on Kubernetes with Pingdom</a> was originally published in <a href="https://medium.com/stakater">Stakater</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating uptime monitoring on Kubernetes with Statuscake]]></title>
            <link>https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-statuscake-dd203d2bac65?source=rss-d8b3ae5447e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd203d2bac65</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[statuscake]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[uptime]]></category>
            <dc:creator><![CDATA[Stakater]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 21:25:11 GMT</pubDate>
            <atom:updated>2018-08-21T06:00:40.844Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="http://stakater.com/?utm_source=automating-uptime-monitoring-on-kubernetes-with-statuscake-dd203d2bac65&amp;utm_medium=blog"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKZ4GIxBnnkKhRr50_HqYA.png" /></a></figure><p>Monitoring uptime and availability of your microservices and receiving alerts when things go down is very critical to meet your SLA and ensure business continuity. StatusCake is a hosted service for uptime monitoring and alerting which can be used with Kubernetes services. It helps you to aggregate alerts in one handy view and efficiently pipe them to the alerting method of your choice.</p><h3>Statuscake features</h3><p>StatusCake has the following features out of the box.</p><ul><li><strong>Uptime monitoring</strong>: Monitor your application availability automatically from over 28 countries worldwide</li><li><strong>Domain monitoring</strong>: You get an alert when it’s time to renew domain or when domain DNS records have been changed.</li><li><strong>Pagespeed Monitoring</strong> : StatusCake provides Pagespeed type tests to fully collect and analyse data on load time for websites and individual pages</li><li><strong>SSL Certificate Monitoring</strong>: You always get alerted when SSL certificates are due for renewal</li><li><strong>Server Monitoring</strong>: You get alerted when certain RAM, CPU and Disk usage are thresholds are exceeded</li><li>Monitor through HTTP, HEAD, TCP, DNS, SMTP, SSH, PING and PUSH protocols</li><li>Management of complex alerting rules with PagerDuty</li><li><strong>Virus Scanning</strong>: StatusCake virus scan alerts you when a threat is detected. It searches for trojans, viruses, malware &amp; other malicious threats on your website.</li><li><strong>Reporting</strong>: Get detailed uptime &amp; speed tests reports delivered via email manually or by setting these up on a daily/weekly/monthly schedule.</li></ul><p>StatusCake gives you many options to decide when and how often to be contacted when there is an alert triggered by Kubernetes Ingress monitoring. Contact method can be Email, SMS, Push notifications for Android &amp; iOS, or through integration with third party application like PagerDuty.</p><h3>Configuring for multiple services</h3><p>Kubernetes Ingress is an object that provides external access to the services in a cluster via HTTP. Ingress is often used for SSL termination, load balancing, and name-based virtual hosting to the cluster internal services.</p><p>The problem most experience is how to configure monitoring for multiple or many multiples of kubernetes ingresses, especially in microservices architectures, and get alerted when they are down or unhealthy. Ingress Monitor Controller was created to address this problem. It will continuously monitor Kubernetes ingresses liveness/change and automatically update URL endpoint configured in StatusCake.</p><p>When Ingress Monitor Controller has been configured, it will always register an ingress automatically when created, so that Statuscake can alert you through email, slack channel, SMS or any other alert means whenever the service may be down. This should help you avoid a 3am call by ensuring quick response to issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*4WhReq6fWPexTYo4Wj-Nxg.png" /></figure><h3>Monitoring for Kubernetes</h3><p>StatusCake features that are of more interest to us in relation to monitoring of Kubernetes services are:</p><p><strong>Uptime checking with HTTP type tests</strong></p><p>StatusCake uptime test ensures that the service being monitored is always up and running without errors. An alert is triggered when the service is down, or when there are errors in the application. Since HTTP is a standard protocol used in Kubernetes cluster service deployment, this is the type of test that will be used with Ingress Monitor Controller.</p><p><strong>Alerting to Slack</strong></p><p>Slack is a powerful notification service supported by StatusCake. It is integrated with StatusCake for receiving and assigning alerts. The fact that slack runs on PC, macOS, Android and iOS makes it a good choice for sending StatusCake notifications to the user.</p><p>With the StatusCake-Slack integration, you easily push alert data to Slack automatically whenever there’s a problem.</p><p><strong>Alerting to Email</strong></p><p>StatusCake also support notifications via email. This is the easiest method since you only need to add Contact group on StatusCake UI, then provide a list of email address that should receive alerts. When the service is down, you’ll get an email like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YOSQPkNRg4RA89QY" /></figure><p><strong>Deploying statuscake to Kubernetes to monitor a service</strong></p><p>StatusCake monitoring of Kubernetes services is done with the help of Ingress Monitor Controller (IMC). IMC is responsible for collection of service metrics on all or specific namespace and pushing the data to StatusCake.</p><h3>Ingress Monitor Controller</h3><p>Ingress Monitor Controller is a tool designed by the <a href="http://stakater.com/">Stakater</a> team to automate the management of URL endpoint monitors in StatusCake using kubernetes events. Other supported monitors are <a href="https://uptimerobot.com/">UptimeRobot</a> and <a href="https://pingdom.com/">Pingdom</a>, but since the code is opensource and extendable, it is easy to implement support for other uptime checkers by creating a custom monitor service interface.</p><p>Below are some features of Ingress Monitor Controller:</p><ul><li>It automatically creates new URL endpoint monitors in StatusCake whenever you create a new Ingress, with the required annotation, on your Kubernetes Cluster.</li><li>IMC will automatically update URL endpoint monitors in StatusCake when ingresses on Kubernetes are updated.</li><li>It will also automatically delete URL endpoint monitors in StatusCake for an Ingress that has been deleted on the cluster.</li><li>It can be configured globally or per namespace as well depending on the need</li></ul><p>The Ingress Monitor Controller watches Ingresses that are created in the cluster, and if the particular ingress is annotated accordingly, i.e. with `monitor.stakater.com/enabled: “true”`, then IMC registers a monitor for that endpoint with Statuscake.</p><p>Depending on the requirement, the Ingress Monitor Controller can be configured at a global level, to monitor all namespaces of the cluster, or it can be configured to watch a specific namespace only. This can be configured via a `watchNamespace` property in the config map.</p><h3>Configuring Ingress Monitor Controller with StatusCake</h3><p>I’ll take you through a step by step deployment of Ingress Monitor Controller on your Kubernetes cluster. I assume you already have an active StatusCake account, if you don’t have one, you can <a href="https://app.statuscake.com/Try/">signup</a> for one.</p><p>Once your account is ready, you’ll need to obtain the following details to be used on Ingress Monitor Controller:</p><ul><li>StatusCake Username</li><li>StatusCake API Key</li><li>StatusCake API URL</li><li>StatusCake contact list/group</li></ul><p>To obtain API Key, login to StatusCake dashboard and navigate to <strong>ACCOUNT</strong> &gt; <strong>User Details</strong> &gt; <strong>API Key</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j3OeXmBdZDPT0P0F" /></figure><p>At the bottom, you’ll see <strong>Endpoint</strong>: <a href="https://app.statuscake.com/API/">https://app.statuscake.com/API/</a>, this will be your API URL. Username is on <strong>Account</strong> &gt; <strong>User Details</strong> &gt; <strong>Username</strong></p><p>Note these values since we will use them later when deploying Ingress Monitor Controller to Kubernetes Cluster. Contact Groups are managed under <strong>Contacts &gt; Create Group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mgekf8KXmfPBhzPR" /></figure><p>To ensure we have clean test environment, a test namespace will be used to demonstrate the deployment. I have a three nodes cluster that I’ll use for this demo:</p><pre>$ <strong>kubectl get nodes</strong><br>NAME STATUS ROLES AGE VERSION<br>k8s-master Ready master 43m v1.11.0<br>k8s-node-01 Ready &lt;none&gt; 15m v1.11.0<br>k8s-node-02 Ready &lt;none&gt; 10m v1.11.0</pre><h3>Step 1: Create a test namespace</h3><p>Create a test namespace on Kubernetes using kubectl command line tool:</p><pre>$ kubectl create <strong>namespace</strong> test-<strong>namespace</strong><br><strong>namespace</strong>/test-<strong>namespace</strong> created</pre><p>Check if the newly created namespace is shown on the system:</p><pre>$ kubectl get namespaces<br>NAME           STATUS AGE<br>default        Active 11m<br>kube-public    Active 11m<br>kube-system    Active 11m<br><strong>test-namespace </strong>Active 17s</pre><h3>Step 2: Create a deployment for our test web application.</h3><p>Let’s create a sample web application container image that listens on a HTTP server on port 80:</p><pre>$ <strong>vim http-app-deployment.yml<br></strong>apiVersion: extensions/v1beta1<br>kind: Deployment<br>metadata:<br>  name: http-app<br>spec:<br>  replicas: 3<br>  template:<br>    metadata:<br>      labels:<br>        app: http-app<br>    spec:<br>      containers:<br>      - name: http-app<br>        image: katacoda/docker-http-server:latest<br>        ports:<br>        - containerPort: 80</pre><p>Deploy it using the command below:</p><pre>$ kubectl apply -n test-namespace -f http-app-deployment.yml<br>deployment.extensions/http-app created</pre><p>Since we specified replica count of 3, three pods will be created.</p><pre>$ kubectl -<strong>n</strong> <strong>test</strong>-namespace get pod<br>NAME                       READY     STATUS    RESTARTS   AGE<br>http-<strong>app</strong>-97f76fcd8-vcxc9   1/1       Running   0          33m<br>http-<strong>app</strong>-97f76fcd8-vtnkt   1/1       Running   0          33m<br>http-<strong>app</strong>-97f76fcd8-xq6cn   1/1       Running   0          33m</pre><h3>Step 3: Expose your Deployment as a Service internally</h3><p>Create a service for deployment above:</p><pre>$ cat http-app-service.yml <br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: http-app-svc<br>  labels:<br>    app: http-app<br>spec:<br>  type: NodePort<br>  ports:<br>  - port: 80<br>    nodePort: 30080<br>  selector:<br>    app: http-app</pre><p>To deploy the service, run the command:</p><pre>$ kubectl apply -n test-namespace -f http-app-service.yml <br>service/http-app-svc created</pre><pre>$ kubectl get service -n test-namespace<br>NAME         TYPE     CLUSTER-IP    EXTERNAL-IP PORT(S)      AGE<br>http-app-svc NodePort 10.110.42.173 &lt;none&gt;      80:30080/TCP 26s</pre><p>Kubernetes Engine makes this Service available on port 30080/TCP on all the nodes in your cluster. Also, note that there is no external IP allocated for this Service. You can do a curl to the cluster IP and port <strong>80 </strong>to confirm if working:</p><pre>$ curl <a href="http://10.110.42.173/">http://10.110.42.173</a><br>&lt;h1&gt;This request was processed <strong>by</strong> host: http-<strong>app</strong>-97f76fcd8-vtnkt&lt;/h1&gt;</pre><pre>$ curl <a href="http://10.110.42.173/">http://10.110.42.173</a><br>&lt;h1&gt;This request was processed by host: http-app-97f76fcd8-vcxc9&lt;/h1&gt;</pre><pre>$ curl <a href="http://10.110.42.173/">http://10.110.42.173</a><br>&lt;h1&gt;This request was processed by host: http-app-97f76fcd8-xq6cn&lt;/h1&gt;</pre><p>We can confirm that the response is coming from three different pods:</p><h4>Step 4: Create an Ingress resource</h4><p>Ingress is a collection of rules and routing policies that govern how external users get access to Kubernetes internal services. For this guide, I deployed<a href="https://github.com/kubernetes/ingress-nginx"> Kubernetes Nginx Ingress</a>. Learn more about using Ingress on <a href="http://kubernetes.io/docs/user-guide/ingress/">kubernetes.io</a></p><p>Once deployed, let’s create an ingress resource with</p><pre>$ cat ingress.yml<br>apiVersion: extensions/v1beta1<br>kind: Ingress<br>metadata:<br>  namespace: test-namespace<br>  name: http-app-svc-ingress<br>  annotations:<br>    kubernetes.io/ingress.class: &quot;nginx&quot;<br>    monitor.stakater.com/enabled: &quot;true&quot;<br>spec:<br>  rules:<br>  - host: service.example.com<br>    http:<br>      paths:<br>      - path: /<br>        backend:<br>          serviceName: http-app-svc <br>          servicePort: 80</pre><p>Deploy it using:</p><pre>$ kubectl apply -f ingress.yml</pre><p>This ingress is linked to our service (<em>http-app-svc</em>) created earlier as the backend. Make sure you have `monitor.stakater.com/enabled: “true”` annotation for IMC to monitor it.</p><h4>Step 5: Deploy Ingress Monitor Controller</h4><p>Ingress Monitor Controller can be deployed using its manifest file. Download it <a href="https://github.com/stakater/IngressMonitorController/blob/master/deployments/kubernetes/ingressmonitorcontroller.yaml">here</a>.</p><p>Open the ingressmonitorcontroller.yaml file you just downloaded, in a text editor to modify configuration.</p><p>In the ClusterRoleBinding resource, specify the namespace</p><pre><strong>namespace</strong>: test-<strong>namespace</strong></pre><p>Next we need to edit <strong>config.yaml </strong>data of the ConfigMap resource to specify configuration parameters for StatusCake.</p><pre>data:<br>  config.yaml: |-<br>    providers:<br>    - name: StatusCake<br>      apiKey: your-statuscake-api<br>      apiURL: https://app.statuscake.com/API/<br>      username: your-status-cake-username<br>    enableMonitorDeletion: true<br>    monitorNameTemplate: &quot;{{.Namespace}}-{{.IngressName}}&quot;</pre><p>Once the changes have been made, you can deploy the controller to the namespace to be monitored, in our case this is <strong>test-namespace</strong> using below kubectl commands:</p><p>Start by deploying ConfigMap</p><pre>$ export  name_space=&quot;test-namespace&quot;<br>$ kubectl apply -f ingressmonitorcontroller.yaml -n $name_space<br>configmap/ingressmonitorcontroller created<br>serviceaccount/ingressmonitorcontroller created<br>clusterrole.rbac.authorization.k8s.io/ingressmonitorcontroller-role created<br>clusterrolebinding.rbac.authorization.k8s.io/ingressmonitorcontroller-role-binding created<br>deployment.extensions/ingressmonitorcontroller created</pre><pre>$ <strong>kubectl -n test-namespace get pods | grep ingressmonitorcontroller<br></strong>ingressmonitorcontroller-84dccb865c-vk45v   1/1  Running   0          11m</pre><p>Once the Ingress Monitor Controller is in running state, login to StatusCake Dashboard and confirm if uptime test for the ingress was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*evJDsYcZmu4b1kvK" /></figure><p>If for any reason the ingress is down, you should receive a notification via Contact group added in StatusCake website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m9XpIe-hOniu8s95" /></figure><p>A sample of down state message with the reason is below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8r1p1yvFoMr7xc1Y" /></figure><p>Here is also a video demonstrating how Ingress Monitor Controller registers monitors for new Ingresses on Statuscake, and removes monitors if the ingress is deleted:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FDDTXKABinmc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DDDTXKABinmc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FDDTXKABinmc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/94fe846eaf20940501d3c7cdd8806992/href">https://medium.com/media/94fe846eaf20940501d3c7cdd8806992/href</a></iframe><figure><a href="http://stakater.com/?utm_source=automating-uptime-monitoring-on-kubernetes-with-statuscake-dd203d2bac65&amp;utm_medium=blog"><img alt="" src="https://cdn-images-1.medium.com/max/700/1*0FANFMBaw8Q8aLuPQJLOOA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd203d2bac65" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stakater/automating-uptime-monitoring-on-kubernetes-with-statuscake-dd203d2bac65">Automating uptime monitoring on Kubernetes with Statuscake</a> was originally published in <a href="https://medium.com/stakater">Stakater</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing resources on a kubernetes cluster using kubectl]]></title>
            <link>https://medium.com/stakater/managing-resources-on-a-kubernetes-cluster-using-kubectl-59a4f4f26a32?source=rss-d8b3ae5447e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/59a4f4f26a32</guid>
            <category><![CDATA[clients]]></category>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kubectl]]></category>
            <category><![CDATA[cluster]]></category>
            <dc:creator><![CDATA[Stakater]]></dc:creator>
            <pubDate>Mon, 22 Jan 2018 02:23:36 GMT</pubDate>
            <atom:updated>2018-08-21T06:16:36.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="http://stakater.com/?utm_source=ingress-monitor-controller-uptime-alerts-for-kubernetes-services-855a6bf48ac0&amp;utm_medium=blog"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKZ4GIxBnnkKhRr50_HqYA.png" /></a></figure><p>If you have been playing with Kubernetes, you should already be familiar with the kubectl command, at least at a basic level. Kubernetes is an open-source tool, originally developed by Google, used for automating deployment and management and auto-scaling of containerized applications. In this article we will be reviewing <strong>kubectl</strong> and what it is used for in Kubernetes.</p><p>kubectl is a powerful command line tool that is used for running commands against Kubernetes clusters. It interacts with the Kubernetes API and its shared state to deploy and manage applications on the Kubernetes cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*-QIGw1oBWo6mKkjnHqi_LA.png" /></figure><h3>Install and Setup kubectl</h3><p>Let’s look at steps required to install kubectl and get it ready for use on Kubernetes cluster. There are different ways you can setup kubectl. One method is by downloading application binary to your OS and make it executable or install it (Windows), and an alternative method involves building the tool from source code available on <a href="https://github.com/kubernetes/kubectl">Github</a>. But the most preferred method is downloading a ready binary file. The method covered here is binary installation.</p><h3>Install kubectl from binary</h3><p>Kubectl binary is available on github and can be installed on Linux, Unix and Windows systems.</p><p><strong>Prerequisites</strong></p><ol><li>Kubernetes cluster already setup. We can do this easily from <a href="http://stakater.com/?utm_source=managing-resources-on-a-kubernetes-cluster-using-kubectl-59a4f4f26a32&amp;utm_medium=blog">http://stakater.com</a></li><li>Internet connection</li><li>curl or wget tool installed (For Mac and Linux) — refer to your OS documentation on how to install it.</li><li>Knowledge of basic Linux/Unix commands; mv, chmod, curl, export — not a must</li></ol><p>With all above prerequisites met, proceed to install kubectl.</p><p>Run the following commands to install the latest release of kubectl, this covers installation for Linux, MacOS, and Windows.</p><h4>Linux and MacOS:</h4><p>Download kubectl binary</p><pre>curl -LO <a href="https://storage.googleapis.com/kubernetes-release/release/%60curl">https://storage.googleapis.com/kubernetes-release/release/`curl</a> -s <a href="https://storage.googleapis.com/kubernetes-release/release/stable.txt%60/bin/darwin/amd64/kubectl">https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/darwin/amd64/kubectl</a></pre><p>Move the binary to <strong>/usr/local/bin/</strong> directory and make it executable.</p><pre>mv ./kubectl /usr/local/bin/</pre><pre>chmod +x /usr/local/bin/kubectl</pre><p>Make sure /usr/local/bin/ is in your $PATH.</p><h4>Windows:</h4><p>For Windows, download the binary from this <a href="https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/windows/amd64/kubectl.exe">link</a> and install it like any other normal Windows application.</p><h3>Check the kubectl configuration</h3><p>After successful installation, confirm that kubectl has been properly configured by issuing a command which checks cluster state.</p><pre>$ kubectl cluster-info</pre><pre>Kubernetes master is running at <a href="https://192.168.99.100:8443/">https://192.168.99.100:8443</a><br>To further debug and diagnose cluster problems, use ‘kubectl cluster-info dump’.</pre><p>If you get a URL response as output, then kubectl is correctly configured and ready for use on your cluster. If you get an error from above command you can dump cluster configuration for further troubleshooting using:</p><pre>$ kubectl cluster-info dump</pre><p>To get less content, pipe to head to filter:</p><pre>$ kubectl cluster-info <strong>dump</strong> |head<br>{<br> “selfLink”: “/api/v1/nodes”,<br> “resourceVersion”: “29495”,<br> “Items”: [<br> {<br> “name”: “minikube”,<br> “selfLink”: “/api/v1/nodes/minikube”,<br> “uid”: “86b7bd31-e550–11e7–8389–080027320547”,<br> “resourceVersion”: “29493”,<br> “creationTimestamp”: “2017–12–20T06:39:27Z”,</pre><h4>Enable shell autocompletion for kubectl commands</h4><p>kubectl comes with built-in bash and zsh completion. This autocompletion is generated by kubectl. It can save you a lot of typing and improve your productivity by autocompleting flags and objects, e.g. pod names and namespaces. To configure autocompletion for kubectl, run:</p><pre>echo “source &lt;(kubectl completion bash)” &gt;&gt; ~/.bashrc</pre><p>This will add kubectl autocomplete to your profile so it’s automatically loaded upon any new shell invocation. If you’re using zsh, add the following lines to</p><pre># kubectl bash completion<br>if [ $commands[kubectl] ]; then<br> source &lt;(kubectl completion zsh)<br>fi</pre><p>Confirm changes:</p><pre>$ tail -n 5 ~/.zshrc<br># kubectl bash completion</pre><pre><strong>if</strong> [ $commands[kubectl] ]; <strong>then</strong><br> source &lt;(kubectl completion zsh)<br><strong>fi</strong></pre><p>Now if you type <strong>kubectl </strong>and press enter, it should list all available options:</p><pre>$ kubectl &lt;TAB TWICE&gt;<br>alpha           cluster-info    describe        logs            rollout</pre><pre>annotate        completion      drain           options         run</pre><pre>api-versions    config          edit            patch           scale</pre><pre>apply           convert         exec            plugin          set</pre><pre>attach          cordon          explain         port-forward    taint</pre><pre>auth            cp              expose          proxy           top</pre><pre>autoscale       create          get             replace         uncordon</pre><pre>certificate     delete          label           rolling-update  version</pre><p>Kubectl commands syntax is</p><pre>$ kubectl [command] [TYPE] [NAME] [flags]</pre><p>This syntax apply for all kubectl commands that you run on your terminal. Where <strong>command</strong>, <strong>TYPE</strong>, <strong>NAME</strong>, and <strong>flags</strong> are:</p><p><strong>Command</strong> — This specifies the operation to be performed on a resource, e.g describe, get, delete, create, run, edit, set, convert, label, scale e.t.c</p><p><strong>TYPE</strong> — This specifies a resource type. Note that resource types are case sensitive, and can be singular, plural, or abbreviated forms. For example commands <strong>pod,pods,po </strong>will return same output.</p><p><strong>NAME — </strong>This specifies a resource name, names are case sensitive. If no name is given, details for all resources will be displayed. A resource can be specified by <strong>type</strong> and <strong>name.</strong></p><p><strong>Flags</strong> — Used to specify optional flags which override default values,example, <strong>-s </strong>or —<strong>server </strong>flag is used to specify the address of Kubernetes API Server.</p><h3>Kubectl Common Operations</h3><p>Having looked at kubectl basics, let’s proceed to see common kubectl operations that can be performed on Kubernetes cluster.</p><h3>Create a resource from a file</h3><p>To create a resource on Kubernetes with kubectl from a file or from stdin, use the following command syntax:</p><pre>$ kubectl create -f FILENAME</pre><p>Supported file formats are <strong>JSON</strong> and YAML. So to create a pod from yaml file named <strong>pod.yml, </strong>you’ll run</p><pre>$ kubectl create -f ./pod.yml</pre><pre>pod “mytestserver” created</pre><p>The same pod.yml contents can be passed as stdin to kubectl command as below.</p><pre>$ cat pod1.yml | kubectl create -f -</pre><pre>pod “mytestserver1” created</pre><h3>List resources</h3><p>To list one or more resources, <strong>kubectl get </strong>command is used for this, it supports plain-text output format. A number of resource types are supported. To get all pods in human readable format, use</p><pre>$ kubectl get pods</pre><pre>NAME            READY     STATUS    RESTARTS   AGE</pre><pre>mytestserver    1/1       Running   0          59s</pre><pre>mytestserver1   1/1       Running   0          32s</pre><p>For json output format, use json flag:</p><pre>$ kubectl get pods -o json | head<br>{<br>&quot;apiVersion&quot;: &quot;v1&quot;,<br>&quot;items&quot;: [<br>{<br>&quot;apiVersion&quot;: &quot;v1&quot;,<br>&quot;kind&quot;: &quot;Pod&quot;,<br>&quot;metadata&quot;: {<br>&quot;creationTimestamp&quot;: &quot;2018-01-06T07:00:42Z&quot;,<br>&quot;name&quot;: &quot;mytestserver&quot;,<br>&quot;namespace&quot;: &quot;default&quot;,</pre><p>To list all pods with more information, <strong>wide </strong>flag is used.</p><pre>$ kubectl get pods -o wide</pre><pre>NAME            READY     STATUS    RESTARTS   AGE       IP           NODE<br>mytestserver    1/1       Running   0          5m        172.17.0.4   minikube<br>mytestserver1   1/1       Running   0          5m        172.17.0.5   minikube</pre><p>You can also list more than two resources together by separating them with a comma.</p><pre>$ kubectl get nodes,jobs,events,pods</pre><p>Where <strong>pods,jobs,events </strong>and <strong>nodes </strong>are resource types. You can consult Kubernetes documentation for all resource types available.</p><h4>Display detailed state of resources</h4><p>To display detailed state of a resource with kubectl, the command <strong>describe</strong> is used. This will print debug information about the given resource. As an example, to display the details of the pod with name &lt;pod-name&gt;, use:</p><pre>$ kubectl <strong>describe</strong> pods/&lt;pod-<strong>name</strong>&gt;</pre><p>Example:</p><pre>$ kubectl describe pods/mytestserver<br>Name:         mytestserver</pre><pre>Namespace:    default</pre><pre>Node:         minikube/192.168.99.100</pre><pre>Start Time:   Sat, 06 Jan 2018 10:00:42 +0300</pre><pre>Labels:       &lt;none&gt;</pre><pre>Annotations:  &lt;none&gt;</pre><pre>Status:       Running</pre><pre>IP:           172.17.0.4</pre><pre>Containers:</pre><pre>hello:</pre><pre>Container ID:   docker://7bb649c9d703bb5c78d48ba0b353fd6d391e16d574a3372b9e431cc7ec11e605</pre><pre>Image:          andygrunwald/simple-webserver</pre><pre>Image ID:       docker-pullable://andygrunwald/simple-webserver@sha256:be5665894aa8df984d34334a837fda2886c107137d0a7b1537c7cb47fe92b9b6</pre><pre>Port:           8082/TCP</pre><pre>State:          Running</pre><pre>Started:      Sat, 06 Jan 2018 10:00:48 +0300</pre><pre>Ready:          True</pre><pre>Restart Count:  0</pre><pre>Environment:    &lt;none&gt;</pre><pre>Mounts:</pre><pre>/var/run/secrets/kubernetes.io/serviceaccount from default-token-k8pmr (ro)</pre><pre>Conditions:</pre><pre>Type           Status</pre><pre>Initialized    True</pre><pre>Ready          True</pre><pre>PodScheduled   True</pre><pre>Volumes:</pre><pre>default-token-k8pmr:</pre><pre>Type:        Secret (a volume populated by a Secret)</pre><pre>SecretName:  default-token-k8pmr</pre><pre>Optional:    false</pre><pre>QoS Class:       BestEffort</pre><pre>Node-Selectors:  &lt;none&gt;</pre><pre>Tolerations:     &lt;none&gt;</pre><pre>Events:</pre><pre>Type    Reason                 Age   From               Message</pre><pre>----    ------                 ----  ----               -------</pre><pre>Normal  Scheduled              10m   default-scheduler  Successfully assigned mytestserver to minikube</pre><pre>Normal  SuccessfulMountVolume  10m   kubelet, minikube  MountVolume.SetUp succeeded for volume &quot;default-token-k8pmr&quot;</pre><pre>Normal  Pulling                10m   kubelet, minikube  pulling image &quot;andygrunwald/simple-webserver&quot;</pre><pre>Normal  Pulled                 10m   kubelet, minikube  Successfully pulled image &quot;andygrunwald/simple-webserver&quot;</pre><pre>Normal  Created                10m   kubelet, minikube  Created container</pre><pre>Normal  Started                10m   kubelet, minikube  Started container</pre><p>Similar commands are used for other resource types.</p><h4>Delete resources</h4><p>With <strong>kubectl delete, </strong>you can delete resources from either a file or stdin. To delete service defined in a file, you’ll use <strong>-f </strong>flag followed by the name of the file:</p><pre>$ kubectl delete -f pod1.yaml</pre><pre>pod “mytestserver1” deleted</pre><p>This deletes a service using a type and name that’s specified in the <strong>service.yml </strong>file. To delete all pods including ones that have not been initialized, run</p><pre>$ kubectl <strong>delete</strong> pods --all</pre><pre>pod “mytestserver” deleted<br>pod “mytestserver1” deleted</pre><h4>Execute a command against a container in a pod</h4><p>If you have containers running in Kubernetes and would like to execute commands on these containers, <strong>kubectl exec </strong>comes in handy. Let’s say we have a container called <strong>apache </strong>on pod <strong>web</strong>, If i want to test internet access through pin, I would run:</p><pre>$ kubectl exec web -c &lt;container-name&gt; date</pre><p>Replace <strong>&lt;container-name&gt;</strong> with the name of your container and <strong>date </strong>with the command to be executed on a container.</p><pre>$ kubectl exec mytestserver date</pre><pre>Sat Jan 6 07:18:22 UTC 2018</pre><h4>Print the logs for a container in a pod.</h4><p>At times you need pull logs from a container for troubleshooting issues, this can be achieved using <strong>kubectl logs </strong>command. In below example, assuming you want to print logs on a pod named <strong>mytestserver </strong>with only one container,<strong> </strong>you’ll run:</p><pre>$ kubectl logs mytestserver <br>2018/01/06 07:17:43 Starting webserver and listen on :8082</pre><p>Next command below will return snapshot of previous terminated nginx container logs from pod<strong> prod-web</strong></p><pre>$ kubectl logs -p -c hello-world mytestserver1</pre><p>You can also stream real time logs using <strong>-f </strong>flag:</p><pre>$ kubectl logs -f -c hello-world mytestserver1</pre><pre>2018/01/06 07:17:43 Starting webserver and listen on :8082</pre><p>Other options available are —tail and —since</p><pre>$ kubectl logs --tail=50 mytestserver # Print most recent 50 lines<br>$ kubectl logs --since=3h mytestserver # Print last 3 hours logs</pre><h4>Forward one or more local ports to a pod.</h4><p>If your node has a public IP address and you would like to access service port on a container through host system port, you’ll need to forward ports using <strong>kubectl port-forward</strong> command. The syntax is:</p><pre>$ kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT</pre><p>Below command will forward port 80 on the host to port 80 on the on the pod.</p><pre>$ kubectl port-forward prod-web 80:80</pre><h4>Edit a resource</h4><p>To edit a resource using kubectl command line tool, use <strong>edit </strong>command. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, fallback being vi for Linux and notepad for Windows. The default format is YAML. The syntax is</p><pre>$ kubectl edit (RESOURCE/NAME | -f FILENAME)</pre><p>Have a look at below example which edits pod called <strong>mytestserver1 </strong>using <strong>vim </strong>editor.</p><pre>$ KUBE_EDITOR=”vim” kubectl edit pod mytestserver1</pre><p>Create a secret for use with a Docker registry.</p><p>If you have a docker registry which requires authentication, create a new secret for use in Dockercfg. This will be used by commands like <strong>docker login </strong>command for image pushing and pulling. Commands syntax is as shown</p><pre>$ kubectl create secret docker-registry mydocker-key \<br> --docker-username=test --docker-password=password --docker-email=test@example.com</pre><pre>secret “mydocker-key” created</pre><p>Replace user with your username, password with real password, and email with a valid email address.</p><p>Check for the created secret:</p><pre>$ kubectl get secret <br>NAME                  TYPE                                  DATA      AGE<br><strong>default</strong>-token-k8pmr   kubernetes.io/service-account-token   3         17d<br>mydocker-key          kubernetes.io/dockercfg               1         57s</pre><p>Delete secret:</p><pre>$ kubectl <strong>delete</strong> secret mydocker-<strong>key</strong> <br>secret “mydocker-key” deleted</pre><h4>Apply a configuration to a resource</h4><p>You can apply a configuration to a resource by filename or stdin. If the resource doesn’t exist yet, it will be created. The formats accepted are JSON and YAML. Consider these examples</p><pre># Apply configuration <strong>in</strong> mypod.yml to a pod<br>$ kubectl apply -f ./pod.yml<br>pod “mytestserver” created</pre><pre># Apply the JSON passed into stdin to a pod<br>$ cat mypod.json | kubectl apply -f -</pre><h4>Auto-scale a deployment or replication controller</h4><p>It’s easy to scale a deployment or replication controller using kubectl command. What you need to do is create an autoscaler that automatically chooses and sets thhe number of pods that run in a kubernetes cluster. This autoscaler can automatically increase or decrease number of pods deployed within the system as needed.</p><p>Create deployment</p><pre>$ kubectl <strong>run</strong> hello-node --image=hello-node:v1 --port=8080<br>deployment “hello-node” created</pre><p>Get deployments:</p><pre>$ kubectl get deployments</pre><pre>NAME         DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE<br>hello-node   1         1         1            0           1s</pre><p>Configure autoscaling:</p><pre>$ kubectl autoscale deployment hello-node --min 2 --max 3 <br>deployment “hello-node” autoscaled</pre><p>Again run get deployments command to confirm autoscaling:</p><pre>$ kubectl get deployment</pre><pre>NAME         DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE<br>hello-node   2         2         2            0           4m</pre><pre>$ kubectl get pod</pre><pre>NAME                          READY     STATUS             RESTARTS   AGE<br>hello-node-75ddf8bc9d-d7bqj   0/1       ImagePullBackOff   0          5m<br>hello-node-75ddf8bc9d-sj646   0/1       ImagePullBackOff   0          2m</pre><p>From above output, you can see the number of pods are now two ( set to minimum):</p><p>This will automatically scale a deployment called <strong>hello-node </strong>with a number of pods between <strong>2</strong> and <strong>3</strong>.</p><p>To target average CPU utilization of 70%, use:</p><pre>$ kubectl autoscale deployment hello-node --min=3 --max=7 --cpu-percent=80</pre><h3>Convert config files between different API versions</h3><p>To convert configuration files between different formats, use kubectl convert command. This support both YAML and JSON formats. An input passed to the command can be a filename, directory, or URL. Output format version is specified using <strong>— output-version </strong>tag, if no version is specified, latest will be used.</p><p>To specify a destination, use <strong>-o </strong>flag. The default output will be printed to stdout in YAML</p><p>Examples:</p><pre>$ <strong>kubectl convert -f tests/pod.yml</strong> # convert to latest version and print on stdout<br>apiVersion: v1</pre><pre>items:</pre><pre>- apiVersion: v1</pre><pre>kind: Pod</pre><pre>metadata:</pre><pre>creationTimestamp: null</pre><pre>name: mytestserver</pre><pre>spec:</pre><pre>containers:</pre><pre>- image: andygrunwald/simple-webserver</pre><pre>imagePullPolicy: Always</pre><pre>name: hello</pre><pre>ports:</pre><pre>- containerPort: 8082</pre><pre>protocol: TCP</pre><pre>resources: {}</pre><pre>terminationMessagePath: /dev/termination-log</pre><pre>terminationMessagePolicy: File</pre><pre>dnsPolicy: ClusterFirst</pre><pre>restartPolicy: Never</pre><pre>schedulerName: default-scheduler</pre><pre>securityContext: {}</pre><pre>terminationGracePeriodSeconds: 30</pre><pre>status: {}</pre><pre>$ <strong>kubectl convert -f tests/pod.yml --local -o json</strong> # convert and print to stdout in json format</pre><pre>{</pre><pre>&quot;kind&quot;: &quot;Pod&quot;,</pre><pre>&quot;apiVersion&quot;: &quot;v1&quot;,</pre><pre>&quot;metadata&quot;: {</pre><pre>&quot;name&quot;: &quot;mytestserver&quot;,</pre><pre>&quot;creationTimestamp&quot;: null</pre><pre>},</pre><pre>&quot;spec&quot;: {</pre><pre>&quot;containers&quot;: [</pre><pre>{</pre><pre>&quot;name&quot;: &quot;hello&quot;,</pre><pre>&quot;image&quot;: &quot;andygrunwald/simple-webserver&quot;,</pre><pre>&quot;ports&quot;: [</pre><pre>{</pre><pre>&quot;containerPort&quot;: 8082,</pre><pre>&quot;protocol&quot;: &quot;TCP&quot;</pre><pre>}</pre><pre>],</pre><pre>&quot;resources&quot;: {},</pre><pre>&quot;terminationMessagePath&quot;: &quot;/dev/termination-log&quot;,</pre><pre>&quot;terminationMessagePolicy&quot;: &quot;File&quot;,</pre><pre>&quot;imagePullPolicy&quot;: &quot;Always&quot;</pre><pre>}</pre><pre>],</pre><pre>&quot;restartPolicy&quot;: &quot;Never&quot;,</pre><pre>&quot;terminationGracePeriodSeconds&quot;: 30,</pre><pre>&quot;dnsPolicy&quot;: &quot;ClusterFirst&quot;,</pre><pre>&quot;securityContext&quot;: {},</pre><pre>&quot;schedulerName&quot;: &quot;default-scheduler&quot;</pre><pre>},</pre><pre>&quot;status&quot;: {}</pre><pre>}</pre><pre><strong>$ kubectl convert -f . | kubectl create -f -</strong>   # Convert all files in current directory and create them all</pre><p>Convert to json and redirect output to a file:</p><pre>$ <strong>kubectl convert -f tests/pod.yml --local -o json &gt; pod.json</strong><br>$ <strong>cat pod.json<br></strong><br>{<br>    &quot;kind&quot;: &quot;Pod&quot;,<br>    &quot;apiVersion&quot;: &quot;v1&quot;,<br>    &quot;metadata&quot;: {<br>        &quot;name&quot;: &quot;mytestserver&quot;,<br>        &quot;creationTimestamp&quot;: null<br>    },<br>    &quot;spec&quot;: {<br>        &quot;containers&quot;: [<br>            {<br>                &quot;name&quot;: &quot;hello&quot;,<br>                &quot;image&quot;: &quot;andygrunwald/simple-webserver&quot;,<br>                &quot;ports&quot;: [<br>                    {<br>                        &quot;containerPort&quot;: 8082,<br>                        &quot;protocol&quot;: &quot;TCP&quot;<br>                    }<br>                ],<br>                &quot;resources&quot;: {},<br>                &quot;terminationMessagePath&quot;: &quot;/dev/termination-log&quot;,<br>                &quot;terminationMessagePolicy&quot;: &quot;File&quot;,<br>                &quot;imagePullPolicy&quot;: &quot;Always&quot;<br>            }<br>        ],<br>        &quot;restartPolicy&quot;: &quot;Never&quot;,<br>        &quot;terminationGracePeriodSeconds&quot;: 30,<br>        &quot;dnsPolicy&quot;: &quot;ClusterFirst&quot;,<br>        &quot;securityContext&quot;: {},<br>        &quot;schedulerName&quot;: &quot;default-scheduler&quot;<br>    },<br>    &quot;status&quot;: {}<br>}</pre><h3>Conclusion</h3><p>We have come to the end of our guide on how to manage Kubernetes cluster and resources with <strong>kubectl</strong> command. We started with the installation of kubectl on Windows and Linux, looked at command line syntax for kubectl command tool, and finalized with examples on management of Kubernetes cluster with kubectl command.</p><figure><a href="http://stakater.com/?utm_source=ingress-monitor-controller-uptime-alerts-for-kubernetes-services-855a6bf48ac0&amp;utm_medium=blog"><img alt="" src="https://cdn-images-1.medium.com/max/700/1*0FANFMBaw8Q8aLuPQJLOOA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59a4f4f26a32" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stakater/managing-resources-on-a-kubernetes-cluster-using-kubectl-59a4f4f26a32">Managing resources on a kubernetes cluster using kubectl</a> was originally published in <a href="https://medium.com/stakater">Stakater</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>