$npx -y skills add mjunaidca/mjs-agent-skills --skill kubernetes-essentialsQuick reference for Kubernetes core concepts and kubectl commands. This skill should be used as a refresher for basic K8s operations including pods, deployments, services, configmaps, secrets, and namespaces. Use this skill when working with Kubernetes clusters for Phase IV+ depl
| 1 | # Kubernetes Essentials Skill |
| 2 | |
| 3 | ## Core Concepts Overview |
| 4 | |
| 5 | ### Kubernetes Architecture |
| 6 | |
| 7 | ``` |
| 8 | ┌─────────────────────────────────────────────────────────────────┐ |
| 9 | │ Control Plane │ |
| 10 | │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────┐ │ |
| 11 | │ │ API Server │ │ Scheduler │ │ Controller │ │ etcd │ │ |
| 12 | │ │ │ │ │ │ Manager │ │ │ │ |
| 13 | │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────┘ │ |
| 14 | └─────────────────────────────────────────────────────────────────┘ |
| 15 | │ |
| 16 | ▼ |
| 17 | ┌─────────────────────────────────────────────────────────────────┐ |
| 18 | │ Worker Nodes │ |
| 19 | │ ┌─────────────────────────────────────────────────────────────┐ │ |
| 20 | │ │ Node 1 Node 2 │ │ |
| 21 | │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ |
| 22 | │ │ │ Pod │ │ Pod │ │ Pod │ │ Pod │ │ │ |
| 23 | │ │ │┌───────┐│ │┌───────┐│ │┌───────┐│ │┌───────┐│ │ │ |
| 24 | │ │ ││ Cont. ││ ││ Cont. ││ ││ Cont. ││ ││ Cont. ││ │ │ |
| 25 | │ │ │└───────┘│ │└───────┘│ │└───────┘│ │└───────┘│ │ │ |
| 26 | │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ |
| 27 | │ │ kubelet, kube-proxy kubelet, kube-proxy │ │ |
| 28 | │ └─────────────────────────────────────────────────────────────┘ │ |
| 29 | └─────────────────────────────────────────────────────────────────┘ |
| 30 | ``` |
| 31 | |
| 32 | ### Key Resources |
| 33 | |
| 34 | | Resource | Purpose | Shorthand | |
| 35 | |----------|---------|-----------| |
| 36 | | **Pod** | Smallest deployable unit, runs containers | `po` | |
| 37 | | **Deployment** | Manages ReplicaSets, handles rollouts | `deploy` | |
| 38 | | **Service** | Network endpoint for pods | `svc` | |
| 39 | | **ConfigMap** | Configuration data (non-sensitive) | `cm` | |
| 40 | | **Secret** | Sensitive configuration data | `secret` | |
| 41 | | **Namespace** | Virtual cluster isolation | `ns` | |
| 42 | | **Ingress** | External HTTP/S routing | `ing` | |
| 43 | | **PersistentVolumeClaim** | Storage request | `pvc` | |
| 44 | |
| 45 | ## Essential kubectl Commands |
| 46 | |
| 47 | ### Context and Configuration |
| 48 | |
| 49 | ```bash |
| 50 | # View current context |
| 51 | kubectl config current-context |
| 52 | |
| 53 | # List all contexts |
| 54 | kubectl config get-contexts |
| 55 | |
| 56 | # Switch context |
| 57 | kubectl config use-context my-context |
| 58 | |
| 59 | # Set default namespace |
| 60 | kubectl config set-context --current --namespace=my-namespace |
| 61 | ``` |
| 62 | |
| 63 | ### Getting Information |
| 64 | |
| 65 | ```bash |
| 66 | # List resources |
| 67 | kubectl get pods # Pods in current namespace |
| 68 | kubectl get pods -A # All namespaces |
| 69 | kubectl get pods -o wide # Additional details (node, IP) |
| 70 | kubectl get pods -o yaml # Full YAML output |
| 71 | kubectl get all # All common resources |
| 72 | |
| 73 | # Describe resources (detailed info + events) |
| 74 | kubectl describe pod my-pod |
| 75 | kubectl describe deployment my-deploy |
| 76 | |
| 77 | # View logs |
| 78 | kubectl logs my-pod # Current logs |
| 79 | kubectl logs my-pod -f # Follow logs |
| 80 | kubectl logs my-pod -c container # Specific container |
| 81 | kubectl logs my-pod --previous # Previous container (after crash) |
| 82 | ``` |
| 83 | |
| 84 | ### Creating Resources |
| 85 | |
| 86 | ```bash |
| 87 | # From YAML file |
| 88 | kubectl apply -f manifest.yaml |
| 89 | |
| 90 | # Imperative creation |
| 91 | kubectl create deployment nginx --image=nginx |
| 92 | kubectl create service clusterip nginx --tcp=80:80 |
| 93 | kubectl create configmap my-config --from-literal=key=value |
| 94 | kubectl create secret generic my-secret --from-literal=password=secret123 |
| 95 | |
| 96 | # Generate YAML without applying |
| 97 | kubectl create deployment nginx --image=nginx --dry-run=client -o yaml > deploy.yaml |
| 98 | ``` |
| 99 | |
| 100 | ### Modifying Resources |
| 101 | |
| 102 | ```bash |
| 103 | # Edit in place |
| 104 | kubectl edit deployment my-deploy |
| 105 | |
| 106 | # Scale deployment |
| 107 | kubectl scale deployment my-deploy --replicas=3 |
| 108 | |
| 109 | # Update image |
| 110 | kubectl set image deployment/my-deploy container=image:v2 |
| 111 | |
| 112 | # Patch resource |
| 113 | kubectl patch deployment my-deploy -p '{"spec":{"replicas":5}}' |
| 114 | ``` |
| 115 | |
| 116 | ### Deleting Resources |
| 117 | |
| 118 | ```bash |
| 119 | # Delete by name |
| 120 | kubectl delete pod my-pod |
| 121 | kubectl delete deployment my-deploy |
| 122 | |
| 123 | # Delete from file |
| 124 | kubectl delete -f manifest.yaml |
| 125 | |
| 126 | # Delete all pods in namespace |
| 127 | kubectl delete pods --all -n my-namespace |
| 128 | |
| 129 | # Force delete stuck pod |
| 130 | kubectl delete pod my-pod --grace-period=0 --force |
| 131 | ``` |
| 132 | |
| 133 | ### Executing Commands |
| 134 | |
| 135 | ```bash |
| 136 | # Run command in pod |
| 137 | kubectl exec my-pod -- ls /app |
| 138 | |
| 139 | # Interactive shell |
| 140 | kubectl exec -it my-pod -- /bin/sh |
| 141 | |
| 142 | # Specific container |
| 143 | kubectl exec -it my-pod -c my-container -- /bin/bash |
| 144 | ``` |
| 145 | |
| 146 | ### Port Forwarding |
| 147 | |
| 148 | ```bash |
| 149 | # Forward pod port to local |
| 150 | kubectl port-forward pod/my-pod 8080:80 |
| 151 | |
| 152 | # Forward service port |
| 153 | kubectl port-forward svc/my-service 8080:80 |
| 154 | ``` |
| 155 | |
| 156 | ## Resource Manifests |
| 157 | |
| 158 | ### Pod |
| 159 | |
| 160 | ```yaml |
| 161 | apiVersion: v1 |
| 162 | kind: Pod |
| 163 | metadata: |