K8 pod cheatsheat


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. It is not a process, but an environment for running container(s).

Two ways of using Pods

  • One container per pod
  • Multiple cooperating processes forming a single cohesive unit of service. Each process is a single container.

POD Specification

apiVersion: v1
kind: Pod
metadata:
  name: 
  labels:
    app: 
spec:
  containers:
    - name: 
      image: 
      imagePullPolicy: 
      command: []
      args: []
      env:
        - name: 
          value: 
      lifecycle:
      livenessProbe:
        httpGet:
          path: 
          port: 
          scheme: 
      ports:
        - name: 
          containerPort: 
        - name: 
          containerPort: 
      readinessProbe:
        httpGet:
          path: 
          port: 
          scheme: 
      volumeMounts:
        - name: 
          mountPath: 
          readOnly: 
  volumes:
    - name: 
      configMap:
        name: 

Key Points To Remember

  • Name specified in the manifest is a valid DNS subdomain name

  • Modifying the pod template or switching to a new pod template has no direct effect on the Pods that already exist.If you change the pod template for a workload resource, that resource needs to create replacement Pods that use the updated template.

  • Updating a pod is possible using patch or replace operation, they have limitations on what fields can be updated.

  • All containers in the Pod can access the shared volumes, allowing those containers to share data.

  • Containers within a pod can communicate via
    • localhost ( port space and IP address are shared )
    • inter-process communication
  • Containers can get access to operating system admin capabilities using privileged

kubectl commands

  • creation of pod

    $ kubectl apply -f /path/to/podspec

  • get all pods

    $ kubectl get pods $ kubectl get pods -o wide

  • get specific pod

    $ kubectl get pod

    $ kubectl get pod -o wide

  • details of the pod

    $ kubectl describe pod

  • delete a pod

    $ kubectl delete pod