Start Preparation Smartly

We have the collection to start prepartion smartly.

Start Assessment

Learn Kubernetes | K8s Tutorial for Beginners

  DevOps Tech Hub

116 Followers

Deploy POD in Kubernetes (K8s) cluster


 What is POD?

POD is  the group of  one or  more  containers with shared storage space and network. kubelet service is the responsible to  manage deploy and run the containers and PODs within the kubernetes cluster.

This diagram depicts POD diagram having two  containers  which are dependent each other. Web Server is the container to  server web traffic and File Puller is the another container which is helper container to the main container. Both containers are running in same POD sharing same volume space.

Source: Kubernetes.io

Verify Cluster worker nodes

[root@ ~]$kubectl get nodes
NAME                            STATUS   ROLES    AGE   VERSION
ip-172-31-66-17.ec2.internal    Ready    <none>   17h   v1.18.5
ip-172-31-72-37.ec2.internal    Ready    <none>   17h   v1.18.5
ip-172-31-76-168.ec2.internal   Ready    <none>   17h   v1.18.5
ip-172-31-77-56.ec2.internal    Ready    master   18h   v1.18.5
[iwayQ@ ~]$

Create POD Manifest file

Create "createpod.yaml"  file with below manifest definitions

#Deploy nginx-pod with latest nginx version
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
    env: sandbox

spec:
  containers:
  - name: ngginx-container
    image: nginx

Deploy POD

[root@ ~]$kubectl apply -f createpod.yaml
pod/nginx-pod created
[iwayQ@ ~]$

Get PODs running on the k8s cluster

Below are the various commands to list running PODs with different properties

#Get Running PODs
[root@ ~]$kubectl get pods
NAME        READY   STATUS    RESTARTS   AGE
nginx-pod   1/1     Running   0          40s
#Get Running PODs with wide info
[root@ ~]$kubectl get pods -o wide
NAME        READY   STATUS    RESTARTS   AGE   IP              NODE                           NOMINATED NODE   READINESS GATES
nginx-pod   1/1     Running   0          48s   172.31.140.65   ip-172-31-72-37.ec2.internal   <none>           <none>
#Get Running PODs
[r@oot ~]$kubectl get po
NAME        READY   STATUS    RESTARTS   AGE
nginx-pod   1/1     Running   0          55s
#Get Running PODs with POD label
[root@ ~]$kubectl get pods nginx-pod
NAME        READY   STATUS    RESTARTS   AGE
nginx-pod   1/1     Running   0          4m13s
[root@ ~]$

Describe POD manifest definition

[root@ ~]$kubectl get pods nginx-pod -o yaml

Describe POD description and events related to POD life cycle 

[root@ ~]$kubectl describe pod nginx-pod
Name:         nginx-pod
Namespace:    default
Priority:     0
Node:         ip-172-31-72-37.ec2.internal/172.31.72.37
Start Time:   Sat, 04 Jul 2020 04:20:19 +0000
Labels:       app=nginx
              env=sandbox
Annotations:  cni.projectcalico.org/podIP: 172.31.140.65/32
              cni.projectcalico.org/podIPs: 172.31.140.65/32
Status:       Running
IP:           172.31.140.65
IPs:
  IP:  172.31.140.65
Containers:
  ngginx-container:
    Container ID:   docker://9caa9edd297589f9a4a1966be5994885ebb216e3212c351a45516abdd1b9ca95
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:21f32f6c08406306d822a0e6e8b7dc81f53f336570e852e25fbe1e3e3d0d0133
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sat, 04 Jul 2020 04:20:24 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-p8d6t (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-p8d6t:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-p8d6t
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age    From                                   Message
  ----    ------     ----   ----                                   -------
  Normal  Scheduled  6m1s   default-scheduler                      Successfully assigned default/nginx-pod to ip-172-31-72-37.ec2.internal
  Normal  Pulling    5m59s  kubelet, ip-172-31-72-37.ec2.internal  Pulling image "nginx"
  Normal  Pulled     5m56s  kubelet, ip-172-31-72-37.ec2.internal  Successfully pulled image "nginx"
  Normal  Created    5m56s  kubelet, ip-172-31-72-37.ec2.internal  Created container ngginx-container
  Normal  Started    5m56s  kubelet, ip-172-31-72-37.ec2.internal  Started container ngginx-container
[root@ ~]$

Run commands in POD

[root@ ~]$kubectl exec nginx-pod -- /bin/bash
[r@oot ~]$

Delete POD

[root@ ~]$kubectl delete pod nginx-pod
pod "nginx-pod" deleted
[root ~]$kubectl get pods
No resources found in default namespace.
[root@ ~]$



Previous Next