The pods are the smallest, atomic deployment unit of Kubernetes. when you deploy an application or if you want to run a single job in the Kubernetes cluster it will run with Pods. A pod is not directly a container, a container is not also looking like a Pod. It is an abstraction over containers.
- It can contain 1 to many containers.
- Containers in the same pod can see, share the same network, hostname, and storage attached to the pod.
- If the pod is created individually without any run time abstraction (Replicaset, Deployment, etc) there is no life cycle management applied and care is given to the pod.
- Pods can be labeled and grouped logically, functionally, etc.
- All the attributes defined in the Pod definition file can be found in API ref doc
Here you can find a sample Pod definition/manifest file. the sample file name can be mypoddefinition.yaml
apiVersion: v1 kind: Pod metadata: name: mywebpod labels: app: superweb spec: containers: - name: myweb-container image: nginx:alpine ports: - containerPort: 80
This pod is containing 1 container and using nginx:alpine image and listening on port 80.
You can use kubectl command and create this pod via
kubectl create -f mypoddefinition.yaml And we have many other kubectl commands to manage Pods via command line.
|kubectl create –f mypod.yml||Create the pod with given manifest file|
|kubectl get pods||Get all the pods in default namespace|
|kubectl describe pods <pods-name>||Get more info about a specific pod|
|kubectl get pods –o json/yaml <pods-name>||Get pod definition file in json or yaml format|
|kubectl exec pods <pods-name> ping me.com||execute a command in the pod namespaces(process, user, file, etc)|
|kubectl exec –it pods <pods-name> sh/bash||Login into pod (Start a shell program in the pod namespaces)|
|kubectl logs -f <pod-name>||Get the logs of a pod, -f is tailing logs|
You can do CRUD operations on the pods if you have enough permissions on them.