Notes to Self

Alex Sokolsky's Notes on Computers and Programming

k8s Pods

Listing pods

Short but show labels:

kubectl get pods -A --show-labels --watch


kubectl get pods -n all -o=wide

To count the pods with a specific label:

kubectl get pods  --show-labels --no-headers --selector env=dev | wc -l

Describe all the pods:

kubectl describe pods -n all

Save pod yaml

kubectl get pod rabbit -o=yaml

Replace a pod

kubectl replace --force -f rabbit.yaml

Create an ad-hoc pod

Use kubectl run

kubectl run nginx --image=nginx --port=5701

To generate the POD Manifest YAML file:

kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml

Then cat pod.yaml gives:

apiVersion: v1
kind: Pod
  name: nginx
  - name: nginx
    image: nginx:1.14.2
    - containerPort: 80
    - secretRef:
        name: test-secret

You can specify command line in-place:

kubectl run busybox --image=busybox --command -- sleep 1000

To get an interactive shell within your cluster with an AWS CLI client:

kubectl run ad-hoc --rm -i --tty --image=zulhfreelancer/aws-cli-v2-on-ubuntu -- bash


To modify limits and/or specify taints use --overrides :

kubectl run ad-hoc --rm -i --tty --image=zulhfreelancer/aws-cli-v2-on-ubuntu --overrides='
    "kind": "Pod",
    "spec": {
        "containers": [
                "name": "ad-hoc",
                "stdin": true,
                "stdinOnce": true,
                "tty": true,
                "image": "zulhfreelancer/aws-cli-v2-on-ubuntu",
                "resources": {
                        "cpu": "8000m",
                        "memory": "512Mi"

Note: The above uses quantity notation, resource units. Hence:

Setting cpu to 8 cores may force autoscaler (e.g. karpenter) to allocate a new cluster node.


You specify a toleration for a pod in the PodSpec. Both of the following tolerations “match” the taint created by the kubectl taint line above, and thus a pod with either toleration would be able to schedule onto node1:

- key: "key1"
  operator: "Equal"
  value: "value1"
  effect: "NoSchedule"
- key: "key1"
  operator: "Exists"
  effect: "NoSchedule"

Delete Pod

kubectl delete pod rabbit

The above does not work for static pods

Static Pods

Static pods are defined in /etc/kubernetes/manifests.