Goglides Dev 🌱

Goglides Dev 🌱 is a community of amazing users

We are working on this space so that IT professionals can grow together.

Create account Log in
Balkrishna Pandey
Balkrishna Pandey

Posted on

Kubernetes Deployment For CKA Certification

Kubernetes deployment is the process of setting up and running a distributed application on a Kubernetes cluster. In other words, a deployment is a Kubernetes object that represents a group of pods that are deployed together. It involves deploying the application's containers onto the nodes in the cluster, configuring the networking between the pods, and setting up storage for the application's data. Kubernetes deployment is often used to improve the performance, scalability, and availability of an application.

Kubernetes deployment is based on the concept of pods. A pod is a group of one or more containers that are deployed together on the same host. Pods are the basic unit of deployment in Kubernetes, and they can be used to deploy both stateless and stateful applications.

Stateless applications are those that do not need to maintain any state between restarts. Examples of stateless applications include web servers and database servers. Stateful applications, on the other hand, do need to maintain a state between restarts. Examples of stateful applications include email servers and file servers.

How to create the deployment?

The first step in deploying a Kubernetes application is to create a deployment configuration file. This file contains all the necessary information about the application, including its container images, network settings, and storage requirements. Once the file is created, it can be passed to the Kubernetes create/apply command, which will initialize and launch the application on the cluster.

Let's see this in action,

Create the Yaml file "deployment-nginx.yaml" in your directory and copy the following definition into the file:


apiVersion: apps/v1

kind: Deployment

metadata:

 name: nginx

 labels:

 team: devteam

spec:

 replicas: 3

 selector:      # deployment selector

 matchLabels:     # Deployment selects "app:frontend" pods and monitors them.

  app: frontend    # If one of the pods is killed, K8s looks at how many replicas are desired. If the number of desired replicas is not met, K8s creates more pods.

 template:

 metadata:

  labels:      # If the deployment selector is the same as these labels, deployment follows pods that have these labels.  

  app: frontend    # key: value   

 spec:          

  containers:

  - name: nginx     

   image: nginx:latest  # You can use your own registry if you do not want to use DockerHub. By default, this will use dockerhub.

   ports:

   - containerPort: 80  # This is the port where the application is running inside the container. In this case, Nginx container is running at port 80.

Enter fullscreen mode Exit fullscreen mode

Now, you can create the deployment by running:


kubectl apply -f deployment-nginx.yaml

Enter fullscreen mode Exit fullscreen mode

If you want to see the deployment, you can run:


kubectl get deployments

Enter fullscreen mode Exit fullscreen mode

This should return something like this:


NAME  READY  UP-TO-DATE  AVAILABLE  AGE

nginx  3/3   3      3      29s

Enter fullscreen mode Exit fullscreen mode

You can also get all pods deployed using this deployment as follows:


kubectl get pods -l app=frontend

Enter fullscreen mode Exit fullscreen mode

This should return something like this:


NAME           READY  STATUS  RESTARTS  AGE

nginx-776567f984-9s2jb  1/1   Running  0     55s

nginx-776567f984-sdrns  1/1   Running  0     55s

nginx-776567f984-vxdzw  1/1   Running  0     55s

Enter fullscreen mode Exit fullscreen mode

Discussion (0)