AI Skill Library

Kubernetes Basics

Pods, services, deployments, config maps, ingress, helm charts.

kubernetesdevopscloud
# Kubernetes Basics

## Core objects
- **Pod**: smallest deployable unit, 1+ containers sharing network/storage.
- **Deployment**: manages ReplicaSet for stateless workloads. Rolling updates + rollback.
- **Service**: stable DNS + IP for a set of pods. Types: ClusterIP, NodePort, LoadBalancer.
- **ConfigMap / Secret**: decouple config from image. Mount as env or file.
- **Ingress**: HTTP routing rules -> Services. Needs an Ingress Controller (nginx, traefik).
- **StatefulSet**: ordered, stable pod identities. For databases.
- **PersistentVolume / PVC**: claim storage independent of pod lifecycle.

## Essential kubectl
```bash
kubectl get pods -n <ns>
kubectl describe pod <name>
kubectl logs <pod> -f --tail=100
kubectl exec -it <pod> -- sh
kubectl apply -f manifest.yaml
kubectl rollout status deployment/<name>
kubectl rollout undo deployment/<name>
kubectl scale deployment/<name> --replicas=3
kubectl port-forward svc/<name> 8080:80
```

## Deployment manifest
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 2
  selector:
    matchLabels: { app: api }
  template:
    metadata:
      labels: { app: api }
    spec:
      containers:
        - name: api
          image: my-api:1.0.0
          ports: [{ containerPort: 3000 }]
          resources:
            requests: { cpu: 100m, memory: 128Mi }
            limits: { cpu: 500m, memory: 512Mi }
          readinessProbe:
            httpGet: { path: /health, port: 3000 }
```

## Helm
- Chart = package of K8s manifests with templating.
- `helm install my-release bitnami/postgresql`
- `helm upgrade my-release . -f values.prod.yaml`
- Override values: `--set image.tag=2.0`

## Namespaces
- Logical isolation. Use per team or environment.
- Default service DNS: `<svc>.<namespace>.svc.cluster.local`

API: /api/skills/kubernetes-basics