kubectl basics
Getting started
Section titled “Getting started”On Kestrel, kubectl authenticates via OIDC using the kubelogin plugin, which you install and wire into your kubeconfig yourself — see Set up kubelogin. Once that’s done, if you can run kubectl get ns and see your namespace listed, you’re ready.
kubectl get nsInspecting resources
Section titled “Inspecting resources”get — list resources
Section titled “get — list resources”kubectl get podskubectl get deploymentskubectl get serviceskubectl get allUseful flags:
| Flag | Effect |
|---|---|
-o wide | Show extra columns (node, IP) |
-o yaml | Full YAML output |
--show-labels | Append labels column |
-w | Watch for changes in real time |
describe — detailed view
Section titled “describe — detailed view”describe shows events, conditions, and configuration in human-readable form. Use it when a Pod won’t start or a Service isn’t routing.
kubectl describe pod my-app-7b4f6d8c9-x2lkjkubectl describe service my-appThe Events section at the bottom is where most debugging starts — it tells you about image pull failures, scheduling problems, and readiness probe failures.
logs — container output
Section titled “logs — container output”kubectl logs my-app-7b4f6d8c9-x2lkjkubectl logs -f my-app-7b4f6d8c9-x2lkj # follow (tail -f)kubectl logs my-app-7b4f6d8c9-x2lkj -c sidecar # specific container in a multi-container Podkubectl logs --previous my-app-7b4f6d8c9-x2lkj # logs from the last crashExecuting commands in a container
Section titled “Executing commands in a container”kubectl exec -it my-app-7b4f6d8c9-x2lkj -- /bin/shThis opens an interactive shell inside the container. Use it for ad-hoc debugging — checking files, testing network connectivity, or running one-off commands.
kubectl exec my-app-7b4f6d8c9-x2lkj -- env # print environment variableskubectl exec my-app-7b4f6d8c9-x2lkj -- cat /etc/hosts # check DNS entriesApplying and deleting
Section titled “Applying and deleting”apply — declarative create/update
Section titled “apply — declarative create/update”kubectl apply -f deployment.yamlkubectl apply -f k8s/ # apply every YAML file in a directoryapply is idempotent: run it again with the same manifest and nothing changes.
delete — remove resources
Section titled “delete — remove resources”kubectl delete -f deployment.yamlkubectl delete pod my-app-7b4f6d8c9-x2lkjDeleting a Pod managed by a Deployment just triggers a replacement. To stop the workload, delete the Deployment.
Quick reference
Section titled “Quick reference”| Task | Command |
|---|---|
| List Pods | kubectl get pods |
| Pod details + events | kubectl describe pod <name> |
| Follow logs | kubectl logs -f <pod> |
| Shell into a container | kubectl exec -it <pod> -- /bin/sh |
| Apply a manifest | kubectl apply -f <file> |
| Delete a resource | kubectl delete -f <file> |
| Scale a Deployment | kubectl scale deployment/<name> --replicas=N |
| Rollback a Deployment | kubectl rollout undo deployment/<name> |
| Check rollout status | kubectl rollout status deployment/<name> |
| Port-forward for local testing | kubectl port-forward svc/<name> 8080:80 |
Port forwarding
Section titled “Port forwarding”To test a Service locally without an Ingress:
kubectl port-forward svc/my-app 8080:80Then open http://localhost:8080 in your browser. The tunnel stays open until you press Ctrl+C.
Next steps
Section titled “Next steps”- YAML editing patterns — manifest patterns and common pitfalls
- ArgoCD on Kestrel — how GitOps deploys replace manual
kubectl apply