{"componentChunkName":"component---src-templates-tag-js","path":"/tags/kubernetes/","result":{"data":{"site":{"siteMetadata":{"title":"LoginRadius Blog"}},"allMarkdownRemark":{"totalCount":2,"edges":[{"node":{"fields":{"slug":"/engineering/rest-api-kubernetes/"},"html":"<p>This blog will help you get started on deploying your REST API in Kubernetes. First, we'll set up a local Kubernetes cluster, then create a <a href=\"https://www.loginradius.com/blog/engineering/what-is-an-api/\">simple API</a> to deploy.</p>\n<p>There are already a lot of <a href=\"https://www.quora.com/What-are-the-best-resources-to-learn-Kubernetes\">free resources available</a> explaining basic Kubernetes concepts, so go check those out first if you haven't already. This blog is intended for beginners but assumes you already have a <a href=\"https://www.loginradius.com/blog/engineering/understanding-kubernetes/\">basic understanding of Kubernetes</a> and Docker concepts.</p>\n<h2 id=\"1-set-up-local-kubernetes\" style=\"position:relative;\"><a href=\"#1-set-up-local-kubernetes\" aria-label=\"1 set up local kubernetes permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. Set Up Local Kubernetes</h2>\n<p>There's a couple options for running Kubernetes locally, with the most popular ones including <a href=\"https://github.com/kubernetes/minikube\">minikube</a>, <a href=\"https://github.com/k3s-io/k3s\">k3s</a>, <a href=\"https://github.com/kubernetes-sigs/kind\">kind</a>, <a href=\"https://github.com/ubuntu/microk8s\">microk8s</a>. In this guide, any of these will work, but we will be using k3s because of the lightweight installation.</p>\n<p>Install <a href=\"https://github.com/rancher/k3d\">k3d</a>, which is a utility for running k3s. k3s will be running in Docker, so make sure you have that installed as well. We used k3d v4.0 in this blog.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash</span></code></pre>\n<p>Set up a cluster named test:</p>\n<ul>\n<li>The port flag is for mapping port 80 from our machine to port 80 on the k3s load balancer. This is needed later when we use ingress.</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">k3d cluster create test -p &quot;80:80@loadbalancer&quot;</span></code></pre>\n<p>Optionally, check that your kubeconfig got updated and the current context is correct:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl config view</span>\n<span class=\"grvsc-line\">kubectl config current-context</span></code></pre>\n<p>Optionally, confirm that k3s is running in Docker. There should be two containers up, one for k3s and the other for load balancing:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">docker ps</span></code></pre>\n<p>Make sure that all the pods are running. If they are stuck in pending status, it may be that there is not enough disk space on your machine. You can get more information by using the describe command:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl get pods -A</span>\n<span class=\"grvsc-line\">kubectl describe pods -A</span></code></pre>\n<p>There's a lot of kubectl commands you can try, so I recommend checking out the list of resources and being aware of their short names:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl api-resources</span></code></pre>\n<h2 id=\"2-create-a-simple-api\" style=\"position:relative;\"><a href=\"#2-create-a-simple-api\" aria-label=\"2 create a simple api permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. Create a Simple API</h2>\n<p>We will create a simple API using Express.js.</p>\n<p>Set up the project:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">mkdir my-backend-api && cd my-backend-api</span>\n<span class=\"grvsc-line\">touch server.js</span>\n<span class=\"grvsc-line\">npm init</span>\n<span class=\"grvsc-line\">npm i express --save</span></code></pre>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">// server.js</span>\n<span class=\"grvsc-line\">const express = require(&quot;express&quot;);</span>\n<span class=\"grvsc-line\">const app = express();</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">app.get(&quot;/user/:id&quot;, (req, res) =&gt; {</span>\n<span class=\"grvsc-line\">  const id = req.params.id;</span>\n<span class=\"grvsc-line\">  res.json({</span>\n<span class=\"grvsc-line\">    id,</span>\n<span class=\"grvsc-line\">    name: `John Doe #${id}`</span>\n<span class=\"grvsc-line\">  });</span>\n<span class=\"grvsc-line\">});</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">app.listen(80, () =&gt; {</span>\n<span class=\"grvsc-line\">  console.log(&quot;Server running on port 80&quot;);</span>\n<span class=\"grvsc-line\">});</span></code></pre>\n<p>Optionally, you can try running it if you have Node.js installed and test the endpoint /user/{id} with curl:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">node server.js</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">// request:</span>\n<span class=\"grvsc-line\">curl http://localhost:80/user/123</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">// response: {&quot;id&quot;:&quot;123&quot;,&quot;name&quot;:&quot;John Doe #123&quot;}</span></code></pre>\n<p>Next, add a Dockerfile and .dockerignore:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">// Dockerfile</span>\n<span class=\"grvsc-line\">FROM node:12</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">WORKDIR /usr/src/app</span>\n<span class=\"grvsc-line\">COPY package*.json ./</span>\n<span class=\"grvsc-line\">RUN npm i</span>\n<span class=\"grvsc-line\">COPY . .</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">EXPOSE 80</span>\n<span class=\"grvsc-line\">CMD [&quot;node&quot;, &quot;server.js&quot;]</span></code></pre>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">// .dockerignore</span>\n<span class=\"grvsc-line\">node_modules</span></code></pre>\n<p>Then, build the image and push it to the Docker Hub registry:</p>\n<ul>\n<li>If you want to skip this step, you can use the existing image <a href=\"https://hub.docker.com/r/andyy5/my-backend-api\">here</a>.</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">docker build -t &lt;YOUR_DOCKER_ID&gt;/my-backend-api .</span>\n<span class=\"grvsc-line\">docker push &lt;YOUR_DOCKER_ID&gt;/my-backend-api</span></code></pre>\n<h2 id=\"3-deploy\" style=\"position:relative;\"><a href=\"#3-deploy\" aria-label=\"3 deploy permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>3. Deploy</h2>\n<p>Now, we deploy the image to our local Kubernetes cluster. We use the default namespace.</p>\n<p>Create a deployment:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"12\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl create deploy my-backend-api --image=andyy5/my-backend-api</span></code></pre>\n<ul>\n<li>Alternatively, create a deployment with a YAML file:</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"13\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl create -f deployment.yaml</span></code></pre>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"14\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">// deployment.yaml</span>\n<span class=\"grvsc-line\">apiVersion: apps/v1</span>\n<span class=\"grvsc-line\">kind: Deployment</span>\n<span class=\"grvsc-line\">metadata:</span>\n<span class=\"grvsc-line\">  name: my-backend-api</span>\n<span class=\"grvsc-line\">  labels:</span>\n<span class=\"grvsc-line\">    app: my-backend-api</span>\n<span class=\"grvsc-line\">spec:</span>\n<span class=\"grvsc-line\">  replicas: 1</span>\n<span class=\"grvsc-line\">  selector:</span>\n<span class=\"grvsc-line\">    matchLabels:</span>\n<span class=\"grvsc-line\">      app: my-backend-api</span>\n<span class=\"grvsc-line\">  template:</span>\n<span class=\"grvsc-line\">    metadata:</span>\n<span class=\"grvsc-line\">      labels:</span>\n<span class=\"grvsc-line\">        app: my-backend-api</span>\n<span class=\"grvsc-line\">    spec:</span>\n<span class=\"grvsc-line\">      containers:</span>\n<span class=\"grvsc-line\">      - name: my-backend-api</span>\n<span class=\"grvsc-line\">        image: andyy5/my-backend-api</span></code></pre>\n<p>Create a service:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"15\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl expose deploy my-backend-api --type=ClusterIP --port=80</span></code></pre>\n<ul>\n<li>Alternatively, create a service with a YAML file:</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"16\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl create -f service.yaml</span></code></pre>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"17\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">// service.yaml</span>\n<span class=\"grvsc-line\">apiVersion: v1</span>\n<span class=\"grvsc-line\">kind: Service</span>\n<span class=\"grvsc-line\">metadata:</span>\n<span class=\"grvsc-line\">  name: my-backend-api</span>\n<span class=\"grvsc-line\">  labels:</span>\n<span class=\"grvsc-line\">    app: my-backend-api</span>\n<span class=\"grvsc-line\">spec:</span>\n<span class=\"grvsc-line\">  type: ClusterIP</span>\n<span class=\"grvsc-line\">  ports:</span>\n<span class=\"grvsc-line\">  - port: 80</span>\n<span class=\"grvsc-line\">    protocol: TCP</span>\n<span class=\"grvsc-line\">    targetPort: 80</span>\n<span class=\"grvsc-line\">  selector:</span>\n<span class=\"grvsc-line\">    app: my-backend-api</span></code></pre>\n<p>Check that everything was created and the pod is running:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"18\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl get deploy -A</span>\n<span class=\"grvsc-line\">kubectl get svc -A</span>\n<span class=\"grvsc-line\">kubectl get pods -A</span></code></pre>\n<p>Once the pod is running, the API is accessible within the cluster only. One quick way to verify the deployment from our localhost is by doing port forwarding:</p>\n<ul>\n<li>Replace the pod name below with the one in your cluster</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"19\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl port-forward my-backend-api-84bb9d79fc-m9ddn 3000:80</span></code></pre>\n<ul>\n<li>Now, you can send a curl request from your machine</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"20\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">curl http://localhost:3000/user/123</span></code></pre>\n<p>To correctly manage external access to the services in a cluster, we need to use ingress. Close the port-forwarding and let's expose our API by creating an ingress resource.</p>\n<ul>\n<li>An ingress controller is also required, but k3d by default deploys the cluster with a Traefik ingress controller (listening on port 80).</li>\n<li>Recall that when we created our cluster, we set a port flag with the value \"80:80@loadbalancer\". If you missed this part, go back and create your cluster again.</li>\n</ul>\n<p>Create an Ingress resource with the following YAML file:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"21\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl create -f ingress.yaml</span>\n<span class=\"grvsc-line\">kubectl get ing -A</span></code></pre>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"22\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">// ingress.yaml</span>\n<span class=\"grvsc-line\">apiVersion: networking.k8s.io/v1</span>\n<span class=\"grvsc-line\">kind: Ingress</span>\n<span class=\"grvsc-line\">metadata:</span>\n<span class=\"grvsc-line\">  name: my-backend-api</span>\n<span class=\"grvsc-line\">  annotations:</span>\n<span class=\"grvsc-line\">    ingress.kubernetes.io/ssl-redirect: &quot;false&quot;</span>\n<span class=\"grvsc-line\">spec:</span>\n<span class=\"grvsc-line\">  rules:</span>\n<span class=\"grvsc-line\">  - http:</span>\n<span class=\"grvsc-line\">      paths:</span>\n<span class=\"grvsc-line\">      - path: /user/</span>\n<span class=\"grvsc-line\">        pathType: Prefix</span>\n<span class=\"grvsc-line\">        backend:</span>\n<span class=\"grvsc-line\">          service:</span>\n<span class=\"grvsc-line\">            name: my-backend-api</span>\n<span class=\"grvsc-line\">            port:</span>\n<span class=\"grvsc-line\">              number: 80</span></code></pre>\n<ul>\n<li>Now try it out!</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"23\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">curl http://localhost:80/user/123</span></code></pre>\n<p>If you want to learn more on how to deploy using a managed Kubernetes service in the cloud, such as Google Kubernetes Engine, then check out the excellent guides on the <a href=\"https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/\">official Kubernetes docs</a>.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"date":"February 03, 2021","updated_date":null,"title":"How to Deploy a REST API in Kubernetes","tags":["Kubernetes"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.492537313432836,"src":"/static/efa8ecb370a0a94f380c24981ede2913/ee604/cover.png","srcSet":"/static/efa8ecb370a0a94f380c24981ede2913/69585/cover.png 200w,\n/static/efa8ecb370a0a94f380c24981ede2913/497c6/cover.png 400w,\n/static/efa8ecb370a0a94f380c24981ede2913/ee604/cover.png 800w,\n/static/efa8ecb370a0a94f380c24981ede2913/f3583/cover.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Andy Yeung","github":null,"avatar":null}}}},{"node":{"fields":{"slug":"/engineering/understanding-kubernetes/"},"html":"<p>Kubernetes is a standard container orchestration open-source platform, that is, for managing applications constructed from several, often self-contained runtimes called containers.</p>\n<p>Since the Docker containerization project launched in 2013, <a href=\"/container-security-scanning/\">containers have become increasingly</a> common, but massive distributed containerized apps can become increasingly difficult to coordinate.</p>\n<p>Kubernetes became a central part of the container revolution by making containerized systems significantly more straightforward to handle at scale.</p>\n<p>This blog targets the way modern applications are deployed and consumed. It <a href=\"https://en.wikipedia.org/wiki/Kubernetes\">introduces the</a> importance of Kubernetes, a container Orchestration tool on a basic level, and how it is making Developers more convenient.</p>\n<h3 id=\"what-is-kubernetes\" style=\"position:relative;\"><a href=\"#what-is-kubernetes\" aria-label=\"what is kubernetes permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Kubernetes</h3>\n<p>Kubernetes (also known as k8s) is a container orchestration tool widely used to deploy and update the application without any downtime. It enables auto-scaling of resources in case of an increase/decrease in requests to the server.\nAlso, it provides intelligent management, allocation of resources, and services, which saves a lot of money for us.</p>\n<h3 id=\"benefits-of-kubernetes\" style=\"position:relative;\"><a href=\"#benefits-of-kubernetes\" aria-label=\"benefits of kubernetes permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Benefits of Kubernetes</h3>\n<p>By using Kubernetes, developers can build cloud-native applications with Kubernetes as a runtime framework. Patterns are the tools a developer of Kubernetes requires to construct applications and services based on containers.</p>\n<p><strong>Here are a few benefits of Kubernetes:</strong></p>\n<ul>\n<li>Optimize the resources required to run your enterprise applications, make better use of hardware.</li>\n<li>Monitor and automate deployments and updates of applications.</li>\n<li>Run Stateful Applications, mount, and add room.</li>\n<li>Manage services declaratively, ensuring that the applications deployed always run the way you expected them to run.</li>\n<li>Health-check your apps with auto-placement, auto restart, auto replication, and autoscaling, and self-heal them.</li>\n</ul>\n<h3 id=\"kubernetes-vs-docker\" style=\"position:relative;\"><a href=\"#kubernetes-vs-docker\" aria-label=\"kubernetes vs docker permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Kubernetes vs. Docker</h3>\n<p>Often mistaken as a choice between one or the other, Kubernetes and <a href=\"/production-grade-development-using-docker-compose/\">Docker for running containerized applications</a> are different but complementary technologies.</p>\n<p><a href=\"https://docs.docker.com/get-started/overview/\">Docker</a> lets you put everything you need into a box that can be stored and opened when and where it is required to run your application. It would help if you had a way to handle them once you start boxing up your applications, and that's what Kubernetes does.</p>\n<ol>\n<li>With or without the Docker, Kubernetes can be used.</li>\n<li>The distinction between Docker and Kubernetes refers to the role each plays in your applications' containerization and execution.</li>\n<li>Docker is an open industry standard to package and distribute container applications.</li>\n<li>To deploy, manage, and scale containerized software, Kubernetes uses Docker.</li>\n</ol>\n<h3 id=\"why-do-you-need-kubernetes\" style=\"position:relative;\"><a href=\"#why-do-you-need-kubernetes\" aria-label=\"why do you need kubernetes permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why do you need Kubernetes?</h3>\n<p>Kubernetes will assist you in deploying and managing containerized, legacy, and cloud-native applications, as well as microservice, refactors.</p>\n<p>To meet evolving business demands, the development team needs to build new products and services rapidly. The cloud-native architecture starts with container microservices, allowing faster development and making it easier to transform and optimize existing software.</p>\n<ul>\n<li>With the rise in the number of internet users, it is expected that applications should not have any downtime for maintenance and updates.</li>\n<li>Each organization wants its deployments to scale according to users' needs, i.e., if more user's requests are coming, then more CPU and Memory should be automatically allocated to the deployment; otherwise, the server will crash.</li>\n<li>Furthermore, no one wants to pay more for CPU and Memory on cloud services if there are no such requirements every time. So there should be some intelligent system that effectively allocates and manages the CPU and Memory utilization as per need.</li>\n</ul>\n<p>That is where Kubernetes comes into the picture. It handles all the above requirements effectively and reduces a lot of burden from the developer's shoulders.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 640px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 56.25%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB+ElEQVQoz1WRy4vUQBDG8xd63oN6kQURPHmUBQ+KiIIKevGkAyqCu4K6IIx4UPcwKLiHOJmkk5lMXpuZZJJM59HvbjsRZrX4URRf1Ud3Vxsi9GW4ZIHfAIf5dgtsslzIaKl14jkIzHRXRYGKNeFffYehlBJSIYaFEnbKWiKoIExIoRTyPQFmaVEGZ2m0WumMKVP/hCGFRC0EQXPj2WbvTnr1cTaZNi2sGBco8FvXLqKwrWuCcdc0gv1vpoxz2hyMqv1Hq7ff6tuvir276+22ZjWUSjVxzMfH7cKL0vQsSYIgCMPQH6IsS0MIlm3gpfvr52P4w0affrYXbq1+z2uJa8U4rcraMvG2IpTiISilCKGu63RhcC66Fh6Miov30tEYXn+6vvIwS9cV7xpFSD+YRLip0eDUHkLI+bX7hXFSQHLzRX35QXHtSWVHRGEoMBGctxCyyfduWyVpmmVZHMdJkkipH6ST7M3lZjMHNphZAPie67qOBaut1nESda5ddR2sqgZCvbB+Z5wrIVTvH04+Nc037z+8Pnr35eTk4/jzy8OjX6apdRQFFFgFwkmWx3mebIoozxGjugWzKFtODf2Tcg6U7/YsBnxPeo7WiT3FlindmfKcHQJYynPz06/B5Lg3c8di9pQ553BgaV0MWdd6YMegz6QLlOf9AQERUnCYmUKiAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Kubernetes Features\"\n        title=\"Kubernetes Features\"\n        src=\"/static/5b524143ddc48218845df011bad4e871/6af66/image2.png\"\n        srcset=\"/static/5b524143ddc48218845df011bad4e871/6af66/image2.png 640w\"\n        sizes=\"(max-width: 640px) 100vw, 640px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h3 id=\"technical-aspect\" style=\"position:relative;\"><a href=\"#technical-aspect\" aria-label=\"technical aspect permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Technical Aspect</h3>\n<p>Kubernetes was designed as a highly available cluster of computers connected to work as a single unit. This abstraction level allows us to deploy the application without thinking much about the machines on which the application would run. <em>Kubernetes' role is to automate the distribution of application containers on computer clusters efficiently.</em>  </p>\n<p>A typical computer cluster in Kubernetes consists of:</p>\n<ul>\n<li><strong>Node</strong>: Where we run our applications</li>\n<li><strong>Master</strong>: Used to coordinate the cluster.</li>\n</ul>\n<blockquote>\n<p>The Master is responsible for managing the cluster. The master nodes will coordinate all the activities in your cluster, such as scheduling applications, maintaining their desired state, scaling applications, and rolling new updates. Whereas a Node is a VM or a physical computer that is used as a worker machine in a Kubernetes cluster to  actually, run the application </p>\n</blockquote>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 638px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 56.26959247648903%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAALABQDASIAAhEBAxEB/8QAGAAAAgMAAAAAAAAAAAAAAAAAAAQCAwX/xAAWAQEBAQAAAAAAAAAAAAAAAAACAAH/2gAMAwEAAhADEAAAAXKNRNiQ+W//xAAcEAABAwUAAAAAAAAAAAAAAAAAAQMUAhESM0P/2gAIAQEAAQUCjpelrJIx0a1n/8QAFxEAAwEAAAAAAAAAAAAAAAAAAAEREv/aAAgBAwEBPwGKwyj/xAAZEQADAAMAAAAAAAAAAAAAAAAAAQIDEhP/2gAIAQIBAT8BeStGzpR//8QAHBAAAQMFAAAAAAAAAAAAAAAAAAEQERIycYKh/9oACAEBAAY/AoqUmS7guDZv/8QAGxAAAgEFAAAAAAAAAAAAAAAAABFRARAhMbH/2gAIAQEAAT8hXAQIaMGhQ5zTZ//aAAwDAQACAAMAAAAQl8//xAAYEQACAwAAAAAAAAAAAAAAAAAAARFRYf/aAAgBAwEBPxBOWFmB/8QAGBEAAwEBAAAAAAAAAAAAAAAAAAERIWH/2gAIAQIBAT8QRp1Q6H//xAAdEAEBAAEEAwAAAAAAAAAAAAABEQAQITFhcaHw/9oACAEBAAE/EFV0A2Y299YEmfnubIXsThnIIMb259XRp//Z'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Kubernetes Architecture\"\n        title=\"Kubernetes Architecture\"\n        src=\"/static/1ced09985df47556a5a0c0c0c0fee5ca/8608d/image4.jpg\"\n        srcset=\"/static/1ced09985df47556a5a0c0c0c0fee5ca/8608d/image4.jpg 638w\"\n        sizes=\"(max-width: 638px) 100vw, 638px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p><em>A master node contains processes that continuously watch the deployment for any CPU or Memory requirement and smartly allocated it in the form of new pods to auto-scale the application, which handles the vast amount of requests coming to the server.</em></p>\n<p>Most of the current cloud services like Amazon Web Service(AWS), Microsoft Azure, and Google Cloud come with automatic support for Kubernetes to provide ease in deploying and maintaining application containers.</p>\n<p>A Kubernetes cluster can be deployed on either virtual or physical machines. A software named Minikube can be installed on your local machine that creates a VM on your local machine and deploys a simple cluster containing only one node.\nMinikube provides a CLI through which we can execute commands &#x26; simulate a small-scale Kubernetes cluster.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 709px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 112.3076923076923%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAWCAYAAADAQbwGAAAACXBIWXMAABcSAAAXEgFnn9JSAAAEC0lEQVQ4y3WUS2skVRiG8wP8I7oTdCWCO10JLvUniEtBGFy6ElcKCrqaWSguMgOjYwYGZILJDJMr6XTS3ZXurr5Wd/Wtqrvul1OPX1WlTUKPBw516pz3vOe7vd9WlmXkY5KE9GKPQewXsy9rQ0VMyRiTYKKKtZGGxdkal9+x07jgyLm21DXhC3/G82DGi2DBfjDnZWyzM2pz//AftrUzfqsc8OB4n2fTXnGWY3LsrtypBHbBoW4THsrhq9DiOFpyFNqcJg7PzR7b50fstGs81io8ujhh3x5zEq8KTI7N71TD5Y2Fa5fNOKAduvQTl971HKiAibireRF9FReuD1TuZnmeY/M7VhrdEK4X67ES6z2nnI48HHgZg2GGtcgI3HLPl6/rlHM91hz/WegGGX6sGC1SFk6K68t/mGGvMkYGWHNYLBVxInuuYiX7k3GG5yn8KNtMyqEe8d3vOvd+aPBg16Q3S1mKNQ9rBl/v7fPN4SE7l2WsLvox3+43+OLJET8ed2gMkk3Cs2HAx587vPV+wJffO5h+hLeAn4Yt3qw95h3tL7Z1U1IJ7UnEe7s1trZP+OTgiuH0NYSnA59Pv/J4+6OIez87jN0IR9z8xdB5t/WUD/RnQjgpCJvjkA9farzxZ4XPTlr0zWQzy5VeyE7V4eErl781h8EswV5m7A2XPOqP+cMw2WtLNgReH0Y86Vr8ejXnad+iNYo3Cb08m0aG3hM1SLCTpNyfipftK+jrMJ+VGfUFa/Sh2wJjAFHI3bLJnx1PYSQepSqjIyBb4h+T0vQCfKm/XF4dP5QdqQRf0XXTYq3L1/TT24QZK/Hk7Nzgsj6k1oTLWouaZnNpLeW/QVWCeT4bcdHS0EKfSnfIud6l4sRUrpqcSzhW6XUd5oSxhKCpezSaLnJGS1/R7oTojkttNmYcSTMIVlSFtBsG1GdLGlObrh9TNee0LIeSr4hhuUjE6lRmIiemnTH3pLgj6TCBYilFb4WKmYCcRDpPEstMxGFFLroU7rq8TswqTJjJq0v5WkHKXBRhiRIsiZO1UtiOkr0U28sfEawXi0rU66U3mSuOuiGNecKpqMYNSuB5O6YuhVuV0mgMyvKYCvZEMNoi4UgPJQfZXQsj0WLNiOlK8GujDi3RXNeU7MlFbeGjzQY0FwbaNBSyjJYUsu4suJCi7zg2V0ZKpq5jWDQGqavaOKZpjThsVOm4Ns1RQkeA7ZUnFte5HOm07FBKSnE1iWnbJgf1HLugbiQkcbZOSmlub5xSm0rfi1Iqg5CldJP81Uo3kmwmNJcxl73SZWOqqIr8BoKtGmL1Qm0qJc/wSDqMIZKbWuqmP0p8cvEb0xQ/KLFKjs15iZ2syYrkstlgbzfM/9svBL2BLWn/BQ9neiw2u5MnAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Kubernetes Deployment\"\n        title=\"Kubernetes Deployment\"\n        src=\"/static/c12f6f6850b1659611a58f57b01f6691/4d08a/image1.png\"\n        srcset=\"/static/c12f6f6850b1659611a58f57b01f6691/a6d36/image1.png 650w,\n/static/c12f6f6850b1659611a58f57b01f6691/4d08a/image1.png 709w\"\n        sizes=\"(max-width: 709px) 100vw, 709px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h4 id=\"some-of-the-basic-kubernetes-cli-commands-are\" style=\"position:relative;\"><a href=\"#some-of-the-basic-kubernetes-cli-commands-are\" aria-label=\"some of the basic kubernetes cli commands are permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Some of the basic Kubernetes CLI commands are:</h4>\n<ul>\n<li><strong>kubectl get nodes</strong> - It gets the total number of working nodes available in the k8s cluster.</li>\n<li><strong>kubectl get pods</strong> - It returns the total number of Running pods present in the cluster.</li>\n<li><strong>kubectl create deployment {DEPLOYMENT<em>NAME} --image={IMAGE</em>NAME}</strong>  - It creates a new deployment on given cluster. We need to specify a deployment name to the deployment and the image from which the deployment should be made.</li>\n<li><strong>kubectl logs {POD_NAME}</strong> - It prints the logs for a particular pod specified using pod name. Logs are handy for debugging the application.</li>\n<li><strong>kubectl cluster-info</strong> - It fetches all the metadata related to the cluster. </li>\n<li><strong>kubectl delete pod {POD_NAME}</strong> - It deletes the deployed pods specified using the pod name.</li>\n</ul>\n<h3 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h3>\n<p>There are many benefits of learning Kubernetes as it releases a lot of deployment stress from the developer's shoulders. It helps in auto-scaling, intelligent utilization of available resources, and enables low downtime for maintenance. </p>\n<p>Without k8s, a lot of human effort and money is gone into these things, but with the help of k8s, everything can be automated.</p>\n<p>Since K8s is a vast technology, it is impossible to wrap all things in just one blog. To simplify things, I will be publishing more blogs soon related to <strong>k8s Deployments, ReplicaSets, Services, Ingress Controller, Master and Worker Processes, Kubectl</strong>, etc. Stay connected and keep learning.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"October 26, 2020","updated_date":null,"title":"What is Kubernetes? - A Basic Guide","tags":["Kubernetes","Deployment","Distributed Systems"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/c0eaad61b9cb15dfe35f7a6d2d0f665a/ee604/image3.png","srcSet":"/static/c0eaad61b9cb15dfe35f7a6d2d0f665a/69585/image3.png 200w,\n/static/c0eaad61b9cb15dfe35f7a6d2d0f665a/497c6/image3.png 400w,\n/static/c0eaad61b9cb15dfe35f7a6d2d0f665a/ee604/image3.png 800w,\n/static/c0eaad61b9cb15dfe35f7a6d2d0f665a/f3583/image3.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Prabhat Kumar","github":"prabhatkgupta","avatar":null}}}}]}},"pageContext":{"tag":"Kubernetes"}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}