Kubernetes Administration — Level by Level›Level 3 · Cheat sheet & self-check

Level 3 — Application delivery · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

17 · Deploy an app end to end

Build it

kubectl create namespace shop-webA home for the app
kubectl apply -f deploy.yaml -f svc.yaml -f ingress.yaml -n shop-webDeployment → Service → Ingress
kubectl rollout status deploy/podinfo -n shop-webWait for a rollout
kubectl set image deploy/podinfo podinfo=ghcr.io/stefanprodan/podinfo:6.7.1 -n shop-webRoll out a new version
kubectl rollout undo deploy/podinfo -n shop-webRoll back

Debug hop by hop

kubectl get pods -n shop-web -o wide1. Pods Running and READY?
kubectl get endpointslices -n shop-web2. Service has endpoints?
kubectl run t --rm -it --image=busybox -- wget -qO- http://podinfo.shop-web3. Service works inside the cluster?
kubectl describe ingress podinfo -n shop-web4. Ingress rule, class, address?
curl -v http://podinfo.127.0.0.1.nip.io/5. From outside?

18 · Namespaces & an app with a database

Namespaces & DNS

<service>.<namespace>.svc.cluster.localFull DNS name of a Service
postgres.shop-data (from another namespace)Short form that works across namespaces
kubectl get all -n shop-dataWhat's in a namespace
Secrets and ConfigMaps are namespacedCreate them where the pods run

Database pieces

StatefulSet + volumeClaimTemplatesStable name (postgres-0) and its own PVC
Service with clusterIP: NoneHeadless: DNS for each StatefulSet pod
initContainer: pg_isready -h postgres.shop-dataWait for the DB before starting the app
NetworkPolicy (namespaceSelector + podSelector)Only the app may reach port 5432

19 · HTTPS & TLS termination

Certificates

openssl req -x509 -nodes -newkey rsa:2048 -days 30 -keyout tls.key -out tls.crt -subj '/CN=shop.127.0.0.1.nip.io' -addext 'subjectAltName=DNS:shop.127.0.0.1.nip.io'Self-signed cert for a lab
kubectl create secret tls shop-tls --cert=tls.crt --key=tls.key -n shop-webStore it as a TLS Secret
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.16.2/cert-manager.yamlInstall cert-manager (pick a current release)
kubectl get certificate,certificaterequest -Acert-manager status

ingress-nginx annotations

cert-manager.io/cluster-issuer: lab-caAsk cert-manager for this Ingress's certificate
nginx.ingress.kubernetes.io/ssl-redirect: "true"HTTP → HTTPS (default when TLS is set for the host)
nginx.ingress.kubernetes.io/ssl-passthrough: "true"Passthrough (controller needs --enable-ssl-passthrough)
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"Re-encrypt to the pod

20 · Ingress & egress gateways

Ingress gateway (Gateway API)

kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.1/standard-install.yamlGateway API CRDs (pick a current release)
GatewayClass → Gateway (listeners) → HTTPRoute (rules)Platform owns Gateways, teams own Routes
kubectl get gatewayclass,gateway,httproute -AStatus of each layer

Egress control

NetworkPolicy podSelector: {} + policyTypes: [Egress]Default-deny egress for a namespace
Allow kube-dns on UDP/TCP 53Don't forget DNS
CiliumNetworkPolicy toFQDNsAllow by DNS name (Cilium)
CiliumEgressGatewayPolicy / Istio egress gatewayFixed exit point and source IP

21 · Release strategies: rolling, blue-green, canary

Rolling & blue-green

strategy.rollingUpdate: { maxSurge: 1, maxUnavailable: 0 }Rolling: capacity never drops
strategy.type: RecreateStop all old pods, then start new (downtime)
kubectl patch svc shop -p '{"spec":{"selector":{"app":"shop","version":"green"}}}'Blue-green: switch the Service

Canary

nginx.ingress.kubernetes.io/canary: "true" + canary-weight: "10"ingress-nginx canary Ingress
HTTPRoute backendRefs weights 90 / 10Gateway API canary
Argo Rollouts: steps [ setWeight: 20, pause, analysis ]Automated progressive delivery
kubectl argo rollouts promote|abort <name>Move forward or roll back