Kubernetes Pods
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
A Pod is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.
Basic Pod definition contains 4 main definition: apiVersion
, kind
, metadata
and spec
.
Example: (suppose file name is data.yml)
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Create a pod using the data above in data.yml
kubectl create -f data.yml
Create a pod based on the content of data.yml passed into stdin
cat data.yml | kubectl create -f -
Create new Pod with name = nginx and image name = nginx
kubectl run nginx —image=nginx
Get Pod Details
kubect describe pod <pod-name>
Get all running pods at current cluster with extended details (node, IP and etc)
kubectl get pods -o wide
Delete Pod by name
kubectl delete pod <pod-name>
Get the yaml of one of the Pods running:
kubectl get pods <pod-name> -o yaml
Extract Pod definition to a file:
kubectl get pod <pod-name> -o yaml > pod-definition.yaml
Edit Pod properties
kubectl edit pod <pod-name>