First deployment on Kubernates

In Kubernates deployment, we need to create yaml files. So before going to write our first yaml based deployment with kubernates. I would like to explain common types of deployment in kubernates.

Types of deployment in kubernates

  • Job: Create one or more pods and track the success of the pods. If the specified number of pods execution completed successfully then job is treated as completed. Its same like cron job but instead of a file it’s a service which runs on specified time and complete its job
  • Deployment:May create multiple pods with replication. Basically you are trying to expose it to real world so whole application will get deployed. Its real application deployment which contain multiple services and their interconnect. You can update,rollback and delete the deployments.
  • Pod:Pods can be of two types single container pod or multi container pod.
  • ReplicationController: It ensures that how many minimum pods to be running. It has the capability to bring up or down to specified pods.
  • ReplicaSet: It also ensure how many replicas of pod should be running.It is the replacement of ReplicationController . The difference between ReplicaSet and ReplicationController is that replication controller only support equality based selector and replica set support set based selector. It means it can support expression based selector.
  • Serviceaccount: You will create serviceaccount and use this service account for pulling a private registry from docker/gcr by using imagepullsecrets.

What is service deployment in kubernates


Service:It’s a logical set of pods for specific tasks. It creates load balancing among the pods and assign a DNS name so that we can access/expose a service as an individual identity without worrying about internal pods.

What is Namespace in kubernates

Namespace: It provides additional qualification to resource. This is really helpful when multiple teams are using same clusters .  So there is a possibility of name collision. By using namespace in service we can isolate our services based on namespace as well.

Functionality of namespace:

  • Pod to Pod communication using same namespace
  • Namespaces are the virtual clusters which sits on top of physical cluster
  • Provides logical separation between team and their environments.

Lets start in action


Step 1: create sample-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.15.4
        ports:
        - containerPort: 80

Step 2: Run the command

kubectl create -f sample-deployment.yaml

Output: deployment.apps/nginx-deployment created
Step 3: Run the command

kubectl get deployments

Output:

NAME                           READY     UP-TO-DATE     AVAILABLE            AGE
nginx-deployment          2/2               2                          2                              59s
Step 4: Run the command
kubectl get pods

Output:
NAME READY STATUS RESTARTS AGE
nginx-deployment-75bd58f5c7-b289r 1/1 Running 0 10m
nginx-deployment-75bd58f5c7-j4gqd 1/1 Running 0 10m

Step 5: For template description:

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

Step 6: To delete this deployment
kubectl delete deployment nginx-deployment
Step 7: Run the command kubectl get pods
No resources found.
Step 8: If you want to see the IP address of the service

kubectl get service frontend –watch

Related posts:

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video... Read More about Chandra Shekhar

Latest posts by Chandra Shekhar (see all)