<< All versions
Skill v1.0.0
currentAutomated scan100/100chavangorakh1999/sde-skills/kubernetes-basics
──Details
PublishedNovember 27, 2026 at 12:38 PM
Content Hashsha256:b651ea2292abd9ad...
Git SHA89ddaddb9288
──Files
Files (1 file, 7.9 KB)
SKILL.md7.9 KBactive
SKILL.md · 330 lines · 7.9 KB
name: kubernetes-basics description: "Kubernetes fundamentals for developers: Deployments, Services, ConfigMaps, Secrets, resource limits, health probes, HPA, and kubectl cheatsheet. Use when deploying or debugging an application on Kubernetes." metadata: version: "1.0.0"
Kubernetes for Developers
Context
Kubernetes problem or deployment task: $ARGUMENTS
Core Resource Types
Pod — smallest deployable unit; one or more containersDeployment — manages replica Pods, handles rolling updatesService — stable network endpoint for a set of PodsConfigMap — non-sensitive config as key-value pairsSecret — sensitive config (base64-encoded, not encrypted by default)HPA — Horizontal Pod Autoscaler — scales replicas based on CPU/memoryIngress — HTTP routing rules (URL path → Service)Namespace — logical isolation within a cluster
Complete Application Manifest
yaml
# k8s/deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: apinamespace: productionlabels:app: apiversion: "1.0.0"spec:replicas: 3selector:matchLabels:app: apistrategy:type: RollingUpdaterollingUpdate:maxSurge: 1 # allow 1 extra pod during updatemaxUnavailable: 0 # never take a pod down before a new one is readytemplate:metadata:labels:app: apispec:# Security context for the PodsecurityContext:runAsNonRoot: truerunAsUser: 1001fsGroup: 1001containers:- name: apiimage: ghcr.io/org/app:sha-abc123 # pin to specific digest in productionimagePullPolicy: IfNotPresentports:- containerPort: 3000name: http# Environment from ConfigMap and Secretsenv:- name: NODE_ENVvalue: production- name: PORTvalue: "3000"envFrom:- configMapRef:name: api-config- secretRef:name: api-secrets# Resource limits (required for HPA to work)resources:requests:memory: "256Mi"cpu: "100m" # 100 millicores = 0.1 CPUlimits:memory: "512Mi"cpu: "500m"# Liveness: is the container alive? Restart if fails.livenessProbe:httpGet:path: /health/liveport: httpinitialDelaySeconds: 10periodSeconds: 30failureThreshold: 3# Readiness: is the container ready for traffic? Remove from LB if fails.readinessProbe:httpGet:path: /health/readyport: httpinitialDelaySeconds: 5periodSeconds: 10failureThreshold: 3# Startup probe: give slow-starting apps time to initstartupProbe:httpGet:path: /health/liveport: httpinitialDelaySeconds: 5failureThreshold: 30 # allow up to 5*30=150s to startperiodSeconds: 5# Security context for the containersecurityContext:allowPrivilegeEscalation: falsereadOnlyRootFilesystem: truecapabilities:drop: [ALL]# Mount tmpfs for writable directoriesvolumeMounts:- name: tmpmountPath: /tmpvolumes:- name: tmpemptyDir: {}# Graceful terminationterminationGracePeriodSeconds: 30# Image pull secret for private registryimagePullSecrets:- name: ghcr-credentials
Service and Ingress
yaml
# k8s/service.yamlapiVersion: v1kind: Servicemetadata:name: apinamespace: productionspec:selector:app: api # routes to pods with this labelports:- port: 80targetPort: httpprotocol: TCPtype: ClusterIP # internal only; Ingress exposes externally---# k8s/ingress.yamlapiVersion: networking.k8s.io/v1kind: Ingressmetadata:name: apinamespace: productionannotations:nginx.ingress.kubernetes.io/rate-limit: "100"cert-manager.io/cluster-issuer: "letsencrypt-prod"spec:tls:- hosts: [api.example.com]secretName: api-tlsrules:- host: api.example.comhttp:paths:- path: /pathType: Prefixbackend:service:name: apiport:name: http
ConfigMap and Secrets
yaml
# k8s/configmap.yamlapiVersion: v1kind: ConfigMapmetadata:name: api-confignamespace: productiondata:LOG_LEVEL: infoALLOWED_ORIGINS: https://app.example.comREDIS_URL: redis://redis-service:6379---# k8s/secret.yaml — values must be base64 encoded# echo -n "mysecret" | base64apiVersion: v1kind: Secretmetadata:name: api-secretsnamespace: productiontype: Opaquedata:JWT_ACCESS_SECRET: <base64>JWT_REFRESH_SECRET: <base64>MONGODB_URI: <base64># Production: use External Secrets Operator to sync from Vault/AWS SSM
Horizontal Pod Autoscaler
yaml
# k8s/hpa.yamlapiVersion: autoscaling/v2kind: HorizontalPodAutoscalermetadata:name: api-hpanamespace: productionspec:scaleTargetRef:apiVersion: apps/v1kind: Deploymentname: apiminReplicas: 2maxReplicas: 10metrics:- type: Resourceresource:name: cputarget:type: UtilizationaverageUtilization: 70 # scale up when avg CPU > 70%- type: Resourceresource:name: memorytarget:type: UtilizationaverageUtilization: 80behavior:scaleUp:stabilizationWindowSeconds: 60 # wait 60s before scaling up againscaleDown:stabilizationWindowSeconds: 300 # wait 5min before scaling down (avoid flapping)
kubectl Cheatsheet
bash
# Context and namespacekubectl config get-contextskubectl config use-context my-clusterkubectl config set-context --current --namespace=production# Deploy / updatekubectl apply -f k8s/kubectl rollout status deployment/apikubectl rollout history deployment/api# Rollbackkubectl rollout undo deployment/apikubectl rollout undo deployment/api --to-revision=3# Debugkubectl get pods -n productionkubectl describe pod api-abc123 -n production # events, statuskubectl logs api-abc123 -n production --tail=100 # recent logskubectl logs -l app=api -n production --tail=50 # all pods with labelkubectl exec -it api-abc123 -- sh # shell into pod# Resource usagekubectl top nodeskubectl top pods -n production# Scale manuallykubectl scale deployment api --replicas=5# Port forward (debug without Ingress)kubectl port-forward deployment/api 3000:3000# Events (great for debugging scheduling issues)kubectl get events -n production --sort-by='.lastTimestamp'# Dry run + diff before applyingkubectl apply -f k8s/ --dry-run=serverkubectl diff -f k8s/
Common Deployment Issues
CrashLoopBackOff:→ kubectl describe pod — check Events section→ kubectl logs <pod> --previous — logs from crashed instance→ Check liveness probe isn't too aggressive (reduce periodSeconds)→ Check resource limits aren't too low (OOMKilled)ImagePullBackOff:→ Check image name/tag is correct→ Verify imagePullSecret is configured and validPending (pod not scheduling):→ kubectl describe pod — look for "Insufficient memory/cpu"→ Check node capacity: kubectl describe nodes | grep Allocatable→ Lower resource requests or add nodesReadiness probe failing:→ App may be starting slowly — increase initialDelaySeconds→ Health endpoint may have a bug — test manually: kubectl exec -it <pod> -- wget -qO- localhost:3000/health/ready