Kubernetes For Developers

Introduction

The article explains the basics of Kubernetes for the frontend/backend engineers, in all reality Kubernetes is a very complex tool but it has abstracted all the complexity from developers. But there are a few concepts that are good for the developers to understand. The article covers a few such basics,

  1. Kubernetes Cluster
  2. Deploying a SpringBoot app
  3. Kubectl

Let’s explore.

Kubernetes Cluster

Kubernetes is a platform for running containers, it supports container scaling, container updates, rollback, etc., in short, it’s a container orchestration platform. The Kubernetes cluster is a set of nodes consisting of Master Node and Worker Nodes.

Worker Nodes

Worker Nodes are part of Kubernetes clusters, worker nodes host the Pods, it’s the place where our containerized application runs. Worker nodes handle the traffic to the applications from the outside and across the cluster.

Pods are the deployable objects in Kubernetes, it’s a collection of containers.

Kubernetes for Developers

Every cluster must have one worker node and directly we never interact with these nodes.

Master Node

Worker nodes can be considered as slave nodes and the Master node manages the worker nodes. It is the one that assigns tasks to the worker nodes. Whenever we are intended to make any changes say scaling the pods from 2 to 3 through Kubectl command or making changes through .yaml file like “rolling update” changes etc, it is handled by Master Node, and it then performs the actions.

Deployment

I have deployed a simple spring-boot app to Kubernetes, the app can be found on the docker hub it’s a public repository, sshukla30/ spring-gke-demo. I am using GCP,

Step one is to create a gke cluster using command

gcloud container clusters create gke-app-cluster --num-nodes 2 --machine-type n1-standard-1 --zone us-central1-c

Once it’s created successfully, it can be verified on the GCP console

Step two is deploying an app to Kubernetes using command

kubectl create deployment demo --image=sshukla30/spring-gke-demo

Under workloads deployment can be verified,

Also, we can verify through kubectl command

kubectl get deployments

App instances created by the deployment should be viewed using the get pods command

kubectl get pods

Step three is to allow external traffic

Pods can be exposed to the public internet by creating a Kubernetes LoadBalancer service, name of the deployment is ‘demo’ and the name of the service is ‘demo-service’, try creating the service using the command.

kubectl expose deployment demo --type=LoadBalancer --name=demo-service --port=8080

Step four is to verify the service details, like ‘IP address for sending the request,

kubectl describe services demo-service

Key with the name “LoadBalancer Ingress” is the IP we must use and the port which is exposed is 8080. We can verify using the curl command or by sending requests through the browser, let’s try executing the actuator health and the endpoint ‘items.

curl http://34.71.244.178:8080/items

curl http://34.71.244.178:8080/actuator/health

Kubectl

Kubectl is Command Line Interface (CLI) for Kubernetes, we interact with Kubernetes through Kubectl most of the time. This is exactly what we did in the Deployment step, in all the steps we were interacting with Kubernetes itself, let’s use few other utility commands like checking logs, scaling pods, etc.

Checking pod logs

For checking the logs of specific pods, we need pod names that can be obtained using

kubectl get pods

kubectl logs demo-669cd6cc64-bj742

Scaling Pods.

On our cluster only 1 pod is running so far, let’s scale it to two.

kubectl scale deploy demo --replicas=2

kubectl get pods

Summary

There is a lot more in Kubernetes, but the article's attempt was to highlight a few important basics of Kubernetes, like how to interact with Kubernetes, high-level knowledge of a master, worker nodes, pods, and kubectl also to start working with it by deploying a simple application.


Similar Articles