DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,864 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Sampriti Mitra
Sampriti Mitra

Posted on

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 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Checking the minikube cluster for running pods

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Checking the self-healing capacity of Kubernetes

kubectl delete pod <pod-name>
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›