Kubernetes Commands You’ll Use Most in a VCF Job

This is a cheat sheet for basic k8s commands that vSphere Tanzu / VCF Automation admins can use daily.

Show All deployments

CommandDescription
k get deployments -Ashow all kube deployments

Core Pod & Cluster Visibility

CommandDescription
kubectl get pods -AList all pods across all namespaces
kubectl get endpoints -n namespaceShows the actual pod IP and port
kubectl get pods --all-namespacesSame as above; alternative syntax.
kubectl get pods -A –field-selector status.phase=RunningCheck all running ones
kubectl get pods -n dns –show-labelsShows all the correct labels of the ports
kubectl top pods -A --sort-by=cpuCheck CPU usage
kubectl get pods -n <ansible-awx>Show pods within a namespace
kubectl get nodesView all nodes in the cluster.
kubectl describe pod <pod>View container state, logs
kubectl logs -n cattle-system rancher-6dc8495d9d-4b44g –previous | tail -30View last 30 logs from pod
kubectl describe pod –namespace awx awx-postgres-15-0List with namespace
kubectl describe svc -n dns technitium-technitium-dnsserverShows the full port config

Export/download a pod

CommandDescription
kubectl get svc rancher -n cattle-system -o yamlExport Service
kubectl get deployment uptime-kuma -n monitoring -o yaml > /tmp/uptime-kuma.ymlExport Deployment

eg:

Monitoring & Troubleshooting

CommandDescription
kubectl describe pod <pod>View container state, logs
kubectl describe pod bad-probe-79bc4fbb76-l4tjs -n k8sgpt-labView container state at pod level
kubectl describe pod bad-probe -n k8sgpt-labSame as above ( dont need to give full pod name)
kubectl get pods -n k8sgpt-lab -o wideShows directly in status column
kubectl exec -it <pod> -- /bin/bashOpen an interactive shell inside the pod
kubectl top podsView live CPU/memory usage per pod.
kubectl top nodes
kubectl top pods -A --sort-by=memory
kubectl top pods -A --sort-by=cpu
View resource usage across nodes.
kubectl top pods -n cattle-systemView top usage on namespace cattle-system.
kubectl logs <pod_name> -n <namespace_name>
View logs for a specific pod.
k8sgpt analyze –namespace k8sgpt-labFast scan to check errors
kubectl logs <pod_name> -n <namespace_name> -fStream logs live , this works like tail command
kubectl delete pod <pod_name> -n <namespace_name>
Delete a pod

Debugging & Troubleshooting with AI

CommandDescription
k8sgpt analyze --explain --backend localai --namespace k8sgpt-labAnalyse and explain using AI
k8sgpt analyze –explain –backend localaiScan all pod for any errors
k8sgpt analyze –explain –backend localai –filter Pod –namespace k8sgpt-labFilter analysis to one resource type
k8sgpt analyze –explain –backend localai –output json –namespace k8sgpt-labOutput results as JSON (useful for piping into other tools)
k8sgpt integration listSee what integrations are available like prometheusetc

Deployment & Access

CommandDescription
kubectl apply -f <file>.yamlCreate or update resources from a YAML file
kubectl port-forward <pod> 8080:80Forward local port 8080 to pod port 80.
kubectl get svc -AView all services across namespaces and port it listens
kubectl get svc -A -o wideSame as above plus wide output
kubectl get pvc -AShows all persistent volumes
kubectl get ingress -AView all ingress rules (VCF often uses NSX ALB)

Curl check

CommandDescription
curl -v http://172.16.77.10:30053 | head -1Output of a service

Namespace & Resource Management

CommandDescription
kubectl get nsList all namespaces.
kubectl get all -n <namespace>Show all resources in a namespace.
kubectl delete -f <file>.yamlDelete resources defined in a YAML file

Scaling Resources

CommandDescription
kubectl scale deployment longhorn-ui -n longhorn-system --replicas=0Scale down to zero pods
kubectl scale deployment longhorn-ui -n longhorn-system –replicas=1Scale up to one pod

Minikube Status (Quick Checks)

CommandDescription
minikube statusShow cluster, kubelet, apiserver, and host status
minikube dashboardLaunch the Kubernetes dashboard
minikube start --driver=dockerStart Minikube using Docker driver
minikube ipGet the Minikube node IP.
minikube dashboardLaunch the Kubernetes dashboard
minikube stopStop the cluster.
minikube deleteRemove the cluster completely.

MiniKube Status

awk@ansible:~$ minikube status
minikube
type: Control Plane
host: Stopped
kubelet: Stopped
apiserver: Stopped
kubeconfig: Stopped

Start Minikube

awk@ansible:~$ minikube start
* minikube v1.38.0 on Ubuntu 24.04
* Using the docker driver based on existing profile
* Starting "minikube" primary control-plane node in "minikube" cluster
* Pulling base image v0.0.49 ...
* Restarting existing docker container for "minikube" ...
! Failing to connect to https://registry.k8s.io/ from both inside the minikube container and host machine
* To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
* Preparing Kubernetes v1.35.0 on Docker 29.2.0 ...
* Verifying Kubernetes components...
  - Using image registry.k8s.io/metrics-server/metrics-server:v0.8.0
  - Using image registry.k8s.io/ingress-nginx/controller:v1.14.1
  - Using image gcr.io/k8s-minikube/storage-provisioner:v5
  - Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.6.5
  - Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.6.5
* Verifying ingress addon...
* Enabled addons: storage-provisioner, metrics-server, default-storageclass, ingress

kubectl get pods -A

awk@ansible:~$ kubectl get pods -A
NAMESPACE       NAME                                              READY   STATUS      RESTARTS      AGE
ansible-awx     awx-operator-controller-manager-85d7499f5-rlmj5   2/2     Running     2 (16h ago)   24h
ansible-awx     awx-ubuntu-migration-24.6.0-kl4cp                 0/1     Completed   0             23h
ansible-awx     awx-ubuntu-postgres-15-0                          1/1     Running     1 (16h ago)   24h
ansible-awx     awx-ubuntu-task-6f5b675f6c-wd7n6                  4/4     Running     4 (16h ago)   23h
ansible-awx     awx-ubuntu-web-7569fb7b67-n8nnh                   3/3     Running     3 (16h ago)   23h
default         ee-shell-full                                     1/1     Running     0             4h14m
ingress-nginx   ingress-nginx-admission-create-25b7b              0/1     Completed   0             24h
ingress-nginx   ingress-nginx-admission-patch-2nvm6               0/1     Completed   0             24h
ingress-nginx   ingress-nginx-controller-8675c6b56f-r7qkd         1/1     Running     1 (16h ago)   24h
kube-system     coredns-7d764666f9-fl5t4                          1/1     Running     2 (16h ago)   24h
kube-system     etcd-minikube                                     1/1     Running     2 (16h ago)   24h
kube-system     kube-apiserver-minikube                           1/1     Running     2 (16h ago)   24h
kube-system     kube-controller-manager-minikube                  1/1     Running     2 (16h ago)   24h
kube-system     kube-proxy-tf29n                                  1/1     Running     2 (16h ago)   24h
kube-system     kube-scheduler-minikube                           1/1     Running     2 (16h ago)   24h
kube-system     metrics-server-5778bb4788-kpnr5                   1/1     Running     0             3h41m
kube-system     storage-provisioner                               1/1     Running     5 (16h ago)   24h


Check Ansible namespace

kubectl get pods -n ansible-awx

awk@ansible:~$ kubectl get pods -n ansible-awx
NAME                                              READY   STATUS      RESTARTS      AGE
awx-operator-controller-manager-85d7499f5-rlmj5   2/2     Running     2 (16h ago)   24h
awx-ubuntu-migration-24.6.0-kl4cp                 0/1     Completed   0             23h
awx-ubuntu-postgres-15-0                          1/1     Running     1 (16h ago)   24h
awx-ubuntu-task-6f5b675f6c-wd7n6                  4/4     Running     4 (16h ago)   23h
awx-ubuntu-web-7569fb7b67-n8nnh                   3/3     Running     3 (16h ago)   23h
awk@ansible:~$

Stream logs from a running container

wk@ansible:~$ kubectl describe pod ee-shell
Name:             ee-shell-full
Namespace:        default
Priority:         0
Service Account:  default
Node:             minikube/192.168.49.2
Start Time:       Fri, 31 Jan 2026 11:05:30 +0000
Labels:           <none>
Annotations:      <none>
Status:           Running
IP:               10.244.0.65
IPs:
  IP:  10.244.0.65
Containers:
  ee-shell-full:
    Container ID:  docker://8881a93b237e33bf50318f386ec8cfe9a1565445b4e392cfb2d3cbbeeed36249
    Image:         ubuntu:24.04
    Image ID:      docker-pullable://ubuntu@sha256:cd1dba651b3080c3686ecf4e3c4220f026b521fb76978881737d24f200828b2b
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/bash
      -c

Create a new project directory for AWX

In AWX, yaml files needs to created under this /var/lib/awx/projects and this needs to be done for both the task and web pods

kubectl exec awx-ubuntu-web-XXXX -n ansible-awx -- mkdir -p /var/lib/awx/projects/htop
kubectl exec awx-ubuntu-task-XXXX -n ansible-awx -- mkdir -p /var/lib/awx/projects/htop

Copy playbooks

kubectl cp htop.yaml ansible-awx/awx-ubuntu-web-7569fb7b67-n8nnh:/var/lib/awx/projects/nginxproject/nginx.yaml/
kubectl cp htop.yaml ansible-awx/awx-ubuntu-task-6f5b675f6c-wd7n6:/var/lib/awx/projects/nginxproject/nginx.yaml

Start a shell session inside the pod

kubectl exec -it awx-ubuntu-task-6f5b675f6c-wd7n6 -n ansible-awx -- /bin/bash
kubectl exec -it awx-ubuntu-web-7569fb7b67-n8nnh -n ansible-awx -- /bin/bash

See files in pod


kubectl exec awx-ubuntu-web-7569fb7b67-n8nnh -n ansible-awx -- ls -l /var/lib/awx/projects/htop
kubectl exec awx-ubuntu-task-6f5b675f6c-wd7n6 -n ansible-awx -- ls -l /var/lib/awx/projects/htop

remove files

kubectl exec awx-ubuntu-web-7569fb7b67-n8nnh -n ansible-awx -- rm /var/lib/awx/projects/nginxproject/nginx.yaml
kubectl exec awx-ubuntu-task-6f5b675f6c-wd7n6 -n ansible-awx -- rm /var/lib/awx/projects/nginxproject/nginx.yaml

Installing htop package over yaml in the usual way

ssh awk@172.16.11.122 "apt install htop; exit"
ssh awk@172.16.11.122 "apt list --installed | grep htop; exit"

Installing htop package over yaml via ansible

Define Playbook: Install htop.yml

awk@ansible:~/playbooks$ cat htop.yaml
---
- hosts: all
  become: yes
  become_user: root

  tasks:
    - name: Update apt cache
      ansible.builtin.apt:
        update_cache: true

    - name: Install htop
      ansible.builtin.apt:
        name: htop
        state: present
awk@ansible:~/playbooks$

Apply Changes, Scale, and Roll Back

View Live CPU and Memory Usage with kubectl top

# View resource usage for nodes
kubectl top node

awk@ansible:~$ kubectl top node
NAME       CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
minikube   338m         16%    2869Mi          28%
awk@ansible:~$

View usage for pods in a namespace


awk@ansible:~$ kubectl top node -n ansible-awx
NAME       CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
minikube   361m         18%    2868Mi          28%

Export a pod yml file to expose a port

kubectl get svc rancher -n cattle-system -o yaml > /tmp/rancher-svc.yaml

Edit nodePort and change type: NodePort

kubectl apply -f /tmp/rancher-svc.yaml

Adding colors to K8s

kubecolor makes kubectl output colourful — Running pods green, Failed red, Pending yellow. Much easier to read than plain text.

Installation

curl -Lo /tmp/kubecolor.deb https://github.com/kubecolor/kubecolor/releases/download/v0.5.3/kubecolor_0.5.3_linux_amd64.deb

sudo dpkg -i /tmp/kubecolor.deb

sudo ln -s /usr/bin/kubecolor /usr/local/bin/kubecolor

Configure

echo ‘alias kubectl=kubecolor’ >> ~/.bashrc

echo ‘alias k=kubectl’ >> ~/.bashrc

source ~/.bashrc

watch -n2 kubectl get pods -n stock-platform -o wide

(Visited 16 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.