Core Concepts
Pods, ReplicaSets, Deployments, Services, Ingress, ConfigMaps, and Secrets.
kubectl Commands
kubectl get pods -A
kubectl describe pod/my-pod
kubectl apply -f deployment.yaml
kubectl logs deploy/myapp -f
kubectl exec -it deploy/myapp -- shUsage
get lists resources; describe shows details and events; apply creates or updates from YAML; logs -f streams logs; exec runs a command inside a container.
Manifests
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata: { name: nginx }
spec:
replicas: 2
selector: { matchLabels: { app: nginx } }
template:
metadata: { labels: { app: nginx } }
spec:
containers:
- name: nginx
image: nginx:alpine
---
# service.yaml
apiVersion: v1
kind: Service
metadata: { name: nginx }
spec:
type: ClusterIP
selector: { app: nginx }
ports: [{ port: 80, targetPort: 80 }]Namespaces & Contexts
kubectl get ns
kubectl config get-contexts
kubectl config use-context my-clusterHelm Basics
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-nginx oci://registry-1.docker.io/bitnamicharts/nginxProject: Nginx with ConfigMap
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata: { name: nginx-html }
data:
index.html: |
<h1>Hello from ConfigMap</h1>
---
# deployment mounts the config
apiVersion: apps/v1
kind: Deployment
metadata: { name: nginx }
spec:
replicas: 1
selector: { matchLabels: { app: nginx } }
template:
metadata: { labels: { app: nginx } }
spec:
containers:
- name: nginx
image: nginx:alpine
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: html
configMap: { name: nginx-html }