Docker and Kubernetes Made Relatable – III

Hi everyone!
Welcome to the third part of this series, where we try to relate with kubernetes as a part of dev life.

In the previous articles, we have discussed about containers & images and how to run containers on docker. We discussed about the …


This content originally appeared on DEV Community and was authored by Sampriti Mitra

Hi everyone!
Welcome to the third part of this series, where we try to relate with kubernetes as a part of dev life.

In the previous articles, we have discussed about containers & images and how to run containers on docker. We discussed about the need for Kubernetes. In this article, we will take a closer look at K8s and why it is so essential.

How Do We Guide All Developers To Work in Sync To Provide the Final Product?

Kubernetes: The engineering manager

Kubernetes is an open source container management and deployment platform. It orchestrates virtual machine clusters and schedules containers to operate on those virtual machines depending on their available computational resources and the container’s resource needs.

They can be related with managers, who plan and coordinate developers to deliver projects and make sure they have all the resources required to do so.

We can use K8s to deploy our services, roll out new releases without downtime, and scale (or descale) those services. It is portable, extensible, self-healing, and highly available.

What are pods?

A Kubernetes pod is a group of one or more containers, tied together for the purposes of administration and networking.

In our workspace analogy, pods can be a pair of senior and junior dev, working together on their related tasks. It can also be a dev who is ramped up on the system and is comfortable with working on the tasks alone.

Nodes and Clusters: Workstation that provides resources to the devs

Consider the example of the employee workspace above. Every employee would require resources like a monitor, chair, desk, etc., to function properly. Every employee needs to be assigned these resources by the manager.
A node can be thought of as the workstation that provides these resources and kubernetes, the manager that assigns these stations to the employees.

In Kubernetes, a Node is a worker computer that can be either virtual or physical. A Node can have many pods, and Kubernetes handles pod scheduling among the cluster’s Nodes automatically. Node is the smallest unit for computing. To establish a cluster, nodes share their resources.

Getting Started With Kubectl and Minikube

Kubectl is Kubernetes’ CLI used to interact with Kubernetes API to create and manage clusters. To install kubectl, run the following:

brew install kubectl

What is Minikube?

Minikube is a tool that lets you try out Kubernetes locally. It is a single node K8s cluster on your local machine for purpose of development or trying out K8s. The Minikube tool includes a set of built-in add-ons that can be enabled, disabled and opened in the local Kubernetes environment.

For installing minikube and starting it on MacOS, run the following commands:

brew install minikube
minikube start

Deploying Your Service to Kubernetes

First, push your local docker image that you built into minikube cache by using the following command:

minikube cache add myapp:latest

Deployment: The team goals and structure defined at the start of the year

A deployment provides declarative updates for Pods and ReplicaSets.
In a Deployment, we define a desired state, and the Deployment Controller gradually converts the current state to the desired state. Deployments may be used to build new ReplicaSets or to delete current Deployments and replace them with new Deployments.
Take a look at the deployment file below:

The above deployment file is like a declarative template for pods and replicasets. The above deployment named myapp in {metadata.name}, creates a replicaset to bring up two pods of myapp. Now the {spec.containers.image} gives the image to be pulled to run the container in the pod given by {template.metadata.labels} app:myapp. The deployment knows which pods to manage by the {spec.selector.matchlabels} app:myapp.

What are ReplicaSets?

The goal of a ReplicaSet is to keep a consistent set of replica Pods operating at all times. As a result, it’s frequently used to ensure the availability of a certain number of identical Pods.

Common deployment strategies

  1. Recreate: all existing pods are terminated and new pods are then generated
  2. Rolling: pods are created in a rolling fashion, ramped up slowly until all new pods are running

Creating a K8s deployment

kubectl apply -f deployment.yaml

Checking the minikube cluster for running pods

kubectl get pods

Now try going into the pod and checking whether the app is running:

kubectl exec -it <pod-name> sh
apk update
apk add curl
curl localhost:10000

Checking the self-healing capacity of Kubernetes

kubectl delete pod <pod-name>
kubectl get pods

We should be able to see two pods still running. Since we deleted a pod, the replicaset controller detected it and spun up another one to keep up the desired state of two pods.

Thanks for reading on till the end of this article. In the next post, we will discuss about Kubernetes Services.


This content originally appeared on DEV Community and was authored by Sampriti Mitra


Print Share Comment Cite Upload Translate Updates
APA

Sampriti Mitra | Sciencx (2021-10-29T19:15:16+00:00) Docker and Kubernetes Made Relatable – III. Retrieved from https://www.scien.cx/2021/10/29/docker-and-kubernetes-made-relatable-iii/

MLA
" » Docker and Kubernetes Made Relatable – III." Sampriti Mitra | Sciencx - Friday October 29, 2021, https://www.scien.cx/2021/10/29/docker-and-kubernetes-made-relatable-iii/
HARVARD
Sampriti Mitra | Sciencx Friday October 29, 2021 » Docker and Kubernetes Made Relatable – III., viewed ,<https://www.scien.cx/2021/10/29/docker-and-kubernetes-made-relatable-iii/>
VANCOUVER
Sampriti Mitra | Sciencx - » Docker and Kubernetes Made Relatable – III. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/29/docker-and-kubernetes-made-relatable-iii/
CHICAGO
" » Docker and Kubernetes Made Relatable – III." Sampriti Mitra | Sciencx - Accessed . https://www.scien.cx/2021/10/29/docker-and-kubernetes-made-relatable-iii/
IEEE
" » Docker and Kubernetes Made Relatable – III." Sampriti Mitra | Sciencx [Online]. Available: https://www.scien.cx/2021/10/29/docker-and-kubernetes-made-relatable-iii/. [Accessed: ]
rf:citation
» Docker and Kubernetes Made Relatable – III | Sampriti Mitra | Sciencx | https://www.scien.cx/2021/10/29/docker-and-kubernetes-made-relatable-iii/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.