0% found this document useful (0 votes)
9 views10 pages

Kubernetes Pods

kubernetes

Uploaded by

waffenddy1380
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Kubernetes Pods

kubernetes

Uploaded by

waffenddy1380
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Kubernetes Pods

Vipin Gupta [email protected] www.linuxexpert.in


BE,RHCE,CEH,CCNA,MCSE,MCSA Mobile: 93563-10379
Pod Type of Pods

- Single Container Pod


- Multi Container Pod
Pod Yaml File
pod-without-port-label.yaml
Pod Commands
$ cat pod-without-port-label.yaml
(display the contents of the file)

$ kubectl get pods


(check whether any pod is already running. it says no resources found)

$ kubectl describe pods


(will give very detailed information about pods. till now we have not created any pods, so it is not
showing any output)

$ kubectl create -f pod-without-port-label.yaml


(creates the object specified in yaml file. in our case, object is pod)

$ kubectl get pods


(now initially, it was showing status “ContainerCreating”, then it changed to “Running”)
Pod Commands
$ kubectl get pods -o wide
(with “-o wide”, we will get additional information regarding pod IP and node on which it is scheduled)

$ kubectl describe pods/webserver


(gives detailed information about “webserver” pod. due to lengthy output, we are not interested in
showing the whole output)

$ kubectl describe pods/webserver |tail


(it will show last 10 lines of output)

$ kubectl exec -it webserver sh


(with “kubectl exec” command we can run commands inside container or can enter into container by
using other options “-i” and “-t”. by default, it will take us into first container of pod)

$ kubectl exec -it -c web webserver sh


(we can specify which particular container you want to access in interactive mode. in this case, we want
to enter into “web” container of “webserver” pod)

$ kubectl delete -f pod-without-port-label.yaml


(will delete the pod “webserver”)
Pod Yaml File
pod-curl.yaml
Pod Commands
In the file, we have specified the image pull as “IfNotPresent” which means that we are instructing
to Kubernetes to not pull the image from the registry, if it is already present on the node.

But why we have added the command in container specifications? What is the purpose of this
command and what it is doing. As such this command will just echo the comment “Pod running”
and then go to sleep for 7200 seconds (2 hours). Which means that for 2 hours some process will
keep on running and our container will not get terminated.

What will happen, if we will not specify the command. In that case, your container will get created
and Immediately get terminated. Thus your Pod will never get created.

Then why we did not specify any command during creation of “webserver” pod from “nginx:alpine”
image. This is because when we use any web server image, by default, one daemon process is
always running.
Pod Yaml File
pod-with-port.yaml
Multi Container Pod Yaml File
pod-multi-container.yaml

apiVersion: v1
kind: Pod
metadata:
name: webserver
labels:
app: nginxweb
type: production
ver: v1
spec:
containers:
- name: web
image: nginx:1.16-alpine
- name: curl
image: vipin2411/curl
command: ["/bin/sh", "-c", "while : ;do curl http://localhost:80/; sleep 15; done"]
Pod Creation Using CLI

Creating pods using CLI without specifying “yaml” file. As such, not recommended method, but still
we will go ahead with creating 2 different pods using 2 different images as we did with “yaml“ files.
Four types of objects can be created by using CLI. The objects are Pods, Deployments, Jobs, CronJobs
Which type of object gets created will depend upon the options passed. Here we are interested in
creating pods.

$ kubectl run webserver --image=nginx:alpine --restart=Never


(create pod “webserver” from “nginx:alpine” image. we have defined restart policy as “Never” which
means that if somehow, pod gets terminated, do not restart it. if we are not going to specify restart
option, then deployment (deploy) plus replicaset (rs) object will get created)

$ kubectl run curl --rm --restart=Never --image=vipin2411/curl -i -t -- sh


(it will create pod “curl” in interactive mode. on exit from the pod, pod will automatically gets
terminated due to “--rm” option)

You might also like