kubernetes pod tutorial

kubernetes pod tutorial

a pod is basic unit in kubernetes which consist one more docker containers. Containers in a pod share the same IP address. A Pod is a group of one or more application containers. In this blog post we will discuss what is kubernetes pod. And how to create a pod in kubernetes.

Get the list of Pods

to get the list of pods running in your kubernetes cluster we will use kubernetes get pods command.

master $ kubectl get pods

NAME    READY   STATUS              RESTARTS   AGE
mypod   0/1     ContainerCreating   0          6s

know the node of pod on which it is running

Using '-o wide' option you will get more information about pod. it will show you, on which node pod is running and it will show you the ip of pod.

master $ kubectl get pods -o wide

NAME    READY   STATUS    RESTARTS   AGE     IP          NODE     NOMINATED NODE   READINESS GATES
mypod   1/1     Running   0          3m38s   10.40.0.1   node01   <none>           <none>

know more about pod

to know more about pod we can use describe command. it will give you on which node this pod is running. And it will show you lables of the pod, ip of the pod

master $ kubectl describe pod mypod

Name:               mypod
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               node01/172.17.0.75
Start Time:         Sun, 25 Aug 2019 14:33:45 +0000
Labels:             env=dev
Annotations:        kubectl.kubernetes.io/last-applied-configuration:
                      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"env":"dev"},"name":"mypod","namespace":"default"},"spec":{"contain...
Status:             Running
IP:                 10.40.0.1
Containers:
  mycontainer:
    Container ID:   docker://e23b0113e03130507380900d415ce25c50014529d80fe21b143f76c4f3d91b65
    Image:          mhausenblas/simpleservice:0.5.0
    Image ID:       docker-pullable://mhausenblas/simpleservice@sha256:33f589ea71cc8a0e37a2f4b17c2e3c207a69c2df525aa62ef5451b75638fd966
    Port:           9876/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sun, 25 Aug 2019 14:34:14 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-vdpdn (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-vdpdn:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-vdpdn
    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  6m9s   default-scheduler  Successfully assigned default/mypod to node01
  Normal  Pulling    6m8s   kubelet, node01    Pulling image "mhausenblas/simpleservice:0.5.0"
  Normal  Pulled     5m41s  kubelet, node01    Successfully pulled image "mhausenblas/simpleservice:0.5.0"
  Normal  Created    5m40s  kubelet, node01    Created container mycontainer
  Normal  Started    5m40s  kubelet, node01    Started container mycontainer

IP of the pod

kubectl describe pod <podname> | grep IP

using above command you can find the ip of the pod

show labels of the pod

using --show-lables option you can find the lables of the pod

master $ kubectl get pods --show-labels

NAME    READY   STATUS    RESTARTS   AGE     LABELS
mypod   1/1     Running   0          9m49s   env=dev

Get the pods with particular label

master $ kubectl get pods -l env=dev

NAME    READY   STATUS    RESTARTS   AGE
mypod   1/1     Running   0          12m

by using -l and with label you can find the pods running with that particular labels.

Delete the pods

master $ kubectl delete pod mypod

pod "mypod" deleted

using delete command you can delete the pod.

  • kubernetes pod tutorial
  • pod tutorial
  • pod kubernetes

Leave a Reply

Your email address will not be published. Required fields are marked *