$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill kubernetes-opsDeploy, scale, and manage Kubernetes workloads. Create deployments, services, and configurations, manage cluster resources, troubleshoot pods, and implement production-ready Kubernetes patterns. Use when working with Kubernetes clusters, K8s deployments, or container orchestratio
| 1 | # Kubernetes Operations |
| 2 | |
| 3 | Deploy and manage containerized applications on Kubernetes clusters. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Deploying applications to Kubernetes |
| 9 | - Managing pods, deployments, and services |
| 10 | - Configuring resource limits and scaling |
| 11 | - Troubleshooting Kubernetes workloads |
| 12 | - Setting up networking and ingress |
| 13 | |
| 14 | ## Prerequisites |
| 15 | |
| 16 | - kubectl installed and configured |
| 17 | - Access to a Kubernetes cluster |
| 18 | - Basic understanding of containers |
| 19 | |
| 20 | ## Core Resources |
| 21 | |
| 22 | ### Deployment |
| 23 | |
| 24 | ```yaml |
| 25 | apiVersion: apps/v1 |
| 26 | kind: Deployment |
| 27 | metadata: |
| 28 | name: myapp |
| 29 | labels: |
| 30 | app: myapp |
| 31 | spec: |
| 32 | replicas: 3 |
| 33 | selector: |
| 34 | matchLabels: |
| 35 | app: myapp |
| 36 | template: |
| 37 | metadata: |
| 38 | labels: |
| 39 | app: myapp |
| 40 | spec: |
| 41 | containers: |
| 42 | - name: myapp |
| 43 | image: myapp:1.0.0 |
| 44 | ports: |
| 45 | - containerPort: 8080 |
| 46 | resources: |
| 47 | requests: |
| 48 | memory: "128Mi" |
| 49 | cpu: "100m" |
| 50 | limits: |
| 51 | memory: "256Mi" |
| 52 | cpu: "500m" |
| 53 | livenessProbe: |
| 54 | httpGet: |
| 55 | path: /health |
| 56 | port: 8080 |
| 57 | initialDelaySeconds: 10 |
| 58 | periodSeconds: 10 |
| 59 | readinessProbe: |
| 60 | httpGet: |
| 61 | path: /ready |
| 62 | port: 8080 |
| 63 | initialDelaySeconds: 5 |
| 64 | periodSeconds: 5 |
| 65 | env: |
| 66 | - name: DATABASE_URL |
| 67 | valueFrom: |
| 68 | secretKeyRef: |
| 69 | name: myapp-secrets |
| 70 | key: database-url |
| 71 | ``` |
| 72 | |
| 73 | ### Service |
| 74 | |
| 75 | ```yaml |
| 76 | apiVersion: v1 |
| 77 | kind: Service |
| 78 | metadata: |
| 79 | name: myapp |
| 80 | spec: |
| 81 | selector: |
| 82 | app: myapp |
| 83 | ports: |
| 84 | - port: 80 |
| 85 | targetPort: 8080 |
| 86 | type: ClusterIP |
| 87 | --- |
| 88 | # LoadBalancer for external access |
| 89 | apiVersion: v1 |
| 90 | kind: Service |
| 91 | metadata: |
| 92 | name: myapp-external |
| 93 | spec: |
| 94 | selector: |
| 95 | app: myapp |
| 96 | ports: |
| 97 | - port: 80 |
| 98 | targetPort: 8080 |
| 99 | type: LoadBalancer |
| 100 | ``` |
| 101 | |
| 102 | ### Ingress |
| 103 | |
| 104 | ```yaml |
| 105 | apiVersion: networking.k8s.io/v1 |
| 106 | kind: Ingress |
| 107 | metadata: |
| 108 | name: myapp |
| 109 | annotations: |
| 110 | nginx.ingress.kubernetes.io/rewrite-target: / |
| 111 | spec: |
| 112 | ingressClassName: nginx |
| 113 | tls: |
| 114 | - hosts: |
| 115 | - myapp.example.com |
| 116 | secretName: myapp-tls |
| 117 | rules: |
| 118 | - host: myapp.example.com |
| 119 | http: |
| 120 | paths: |
| 121 | - path: / |
| 122 | pathType: Prefix |
| 123 | backend: |
| 124 | service: |
| 125 | name: myapp |
| 126 | port: |
| 127 | number: 80 |
| 128 | ``` |
| 129 | |
| 130 | ## Configuration Management |
| 131 | |
| 132 | ### ConfigMap |
| 133 | |
| 134 | ```yaml |
| 135 | apiVersion: v1 |
| 136 | kind: ConfigMap |
| 137 | metadata: |
| 138 | name: myapp-config |
| 139 | data: |
| 140 | config.yaml: | |
| 141 | server: |
| 142 | port: 8080 |
| 143 | logging: |
| 144 | level: info |
| 145 | APP_ENV: production |
| 146 | ``` |
| 147 | |
| 148 | ```yaml |
| 149 | # Using ConfigMap |
| 150 | containers: |
| 151 | - name: myapp |
| 152 | envFrom: |
| 153 | - configMapRef: |
| 154 | name: myapp-config |
| 155 | volumeMounts: |
| 156 | - name: config |
| 157 | mountPath: /etc/config |
| 158 | volumes: |
| 159 | - name: config |
| 160 | configMap: |
| 161 | name: myapp-config |
| 162 | ``` |
| 163 | |
| 164 | ### Secret |
| 165 | |
| 166 | ```yaml |
| 167 | apiVersion: v1 |
| 168 | kind: Secret |
| 169 | metadata: |
| 170 | name: myapp-secrets |
| 171 | type: Opaque |
| 172 | stringData: |
| 173 | database-url: postgres://user:pass@host:5432/db |
| 174 | api-key: secret-key-value |
| 175 | ``` |
| 176 | |
| 177 | ```bash |
| 178 | # Create secret from command line |
| 179 | kubectl create secret generic myapp-secrets \ |
| 180 | --from-literal=database-url='postgres://...' \ |
| 181 | --from-file=tls.crt=cert.pem |
| 182 | ``` |
| 183 | |
| 184 | ## kubectl Commands |
| 185 | |
| 186 | ### Resource Management |
| 187 | |
| 188 | ```bash |
| 189 | # Apply configuration |
| 190 | kubectl apply -f deployment.yaml |
| 191 | |
| 192 | # Get resources |
| 193 | kubectl get pods |
| 194 | kubectl get deployments |
| 195 | kubectl get services |
| 196 | kubectl get all -n myapp |
| 197 | |
| 198 | # Describe resource |
| 199 | kubectl describe pod myapp-xxx |
| 200 | |
| 201 | # Delete resource |
| 202 | kubectl delete -f deployment.yaml |
| 203 | kubectl delete pod myapp-xxx |
| 204 | |
| 205 | # Edit resource |
| 206 | kubectl edit deployment myapp |
| 207 | ``` |
| 208 | |
| 209 | ### Debugging |
| 210 | |
| 211 | ```bash |
| 212 | # View logs |
| 213 | kubectl logs myapp-xxx |
| 214 | kubectl logs -f myapp-xxx --tail=100 |
| 215 | kubectl logs myapp-xxx -c sidecar # specific container |
| 216 | |
| 217 | # Execute command |
| 218 | kubectl exec -it myapp-xxx -- /bin/sh |
| 219 | |
| 220 | # Port forward |
| 221 | kubectl port-forward svc/myapp 8080:80 |
| 222 | kubectl port-forward pod/myapp-xxx 8080:8080 |
| 223 | |
| 224 | # View events |
| 225 | kubectl get events --sort-by='.lastTimestamp' |
| 226 | |
| 227 | # Debug pod |
| 228 | kubectl debug myapp-xxx -it --image=busybox |
| 229 | ``` |
| 230 | |
| 231 | ### Scaling |
| 232 | |
| 233 | ```bash |
| 234 | # Manual scaling |
| 235 | kubectl scale deployment myapp --replicas=5 |
| 236 | |
| 237 | # Autoscaling |
| 238 | kubectl autoscale deployment myapp \ |
| 239 | --min=2 --max=10 \ |
| 240 | --cpu-percent=80 |
| 241 | ``` |
| 242 | |
| 243 | ## Horizontal Pod Autoscaler |
| 244 | |
| 245 | ```yaml |
| 246 | apiVersion: autoscaling/v2 |
| 247 | kind: HorizontalPodAutoscaler |
| 248 | metadata: |
| 249 | name: myapp |
| 250 | spec: |
| 251 | scaleTargetRef: |
| 252 | apiVersion: apps/v1 |
| 253 | kind: Deployment |
| 254 | name: myapp |
| 255 | minReplicas: 2 |
| 256 | maxReplicas: 10 |
| 257 | metrics: |
| 258 | - type: Resource |
| 259 | resource: |
| 260 | name: cpu |
| 261 | target: |
| 262 | type: Utilization |
| 263 | averageUtilization: 80 |
| 264 | - type: Resource |
| 265 | resource: |
| 266 | name: memory |
| 267 | target: |
| 268 | type: Utilization |
| 269 | averageUtiliz |