Skip to content

Pods

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes. They are groups of one or more containers.

Requirements

To deploy a Kubernetes Pod the following requirements must be met:

  1. A namespace must be specified, and the user must be a member of the project to which the specified namespace is bound.
  2. It is required that both Pod resources.requests and resources.limits is specified.
  3. requests.memory and limits.memory must be set and must be equal.
  4. requests.cpu must be set. limits.cpu is optional (when not specified, pods will use all free CPU cores available. However, in some circumstances, it might be appropriate to use it).
  5. Enough resources must be available in the namespace quota, see Namespaces section.

An error message will be generated if any of the requirements above are not met.

Below is an example of a Pod yaml specification reserving 0.5 CPUs and 128MiB memory:

testpod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: testpod
  labels:
    app: testapp
spec:
  containers:
    - name: bb
      image: busybox
      command: ["/bin/sh"]
      args: ["-c", "while true; do date && sleep 1; done"]
      resources:
        requests:
          memory: "128Mi"
          cpu: "500m"
        limits:
          memory: "128Mi"

Remember to set your default namespace before continuing.

Deploy pod

This is also used to install other Kubernetes objects using YAML files

kubectl create -f testpod.yaml

Show running

kubectl get pods
NAME      READY   STATUS    RESTARTS   AGE
testpod   1/1     Running   0          56s

Logging

Read the standard output of the pod. The -f option follows any new output.

kubectl logs testpod -f
Thu Jan  5 04:30:58 UTC 2023
Thu Jan  5 04:30:59 UTC 2023
Thu Jan  5 04:31:00 UTC 2023

Access shell

kubectl exec -it testpod -- /bin/sh
/ # uname -a
Linux testpod 4.15.0-193-generic #204-Ubuntu SMP Fri Aug 26 19:20:21 UTC 2022 x86_64 GNU/Linux

Port forward

To access a web server on the pod, running at port 80

kubectl port-forward testpod 8080:80

Then open http://localhost:8080 with your web browser.

Detailed pod specification

kubectl get pods -o=jsonpath='{.items[*].spec}' | jq | less

Delete pod

kubectl delete -f testpod.yaml