#Kubernetes Advanced

Advanced Kubernetes concepts and patterns.


#Ingress

yaml
1apiVersion: networking.k8s.io/v1
2kind: Ingress
3metadata:
4  name: myapp-ingress
5spec:
6  rules:
7  - host: myapp.example.com
8    http:
9      paths:
10      - path: /
11        pathType: Prefix
12        backend:
13          service:
14            name: myapp-service
15            port:
16              number: 80

#StatefulSets

yaml
1apiVersion: apps/v1
2kind: StatefulSet
3metadata:
4  name: postgres
5spec:
6  serviceName: postgres
7  replicas: 3
8  selector:
9    matchLabels:
10      app: postgres
11  template:
12    metadata:
13      labels:
14        app: postgres
15    spec:
16      containers:
17      - name: postgres
18        image: postgres:15
19        volumeMounts:
20        - name: data
21          mountPath: /var/lib/postgresql/data
22  volumeClaimTemplates:
23  - metadata:
24      name: data
25    spec:
26      accessModes: ["ReadWriteOnce"]
27      resources:
28        requests:
29          storage: 10Gi

#ConfigMaps and Secrets

yaml
1# ConfigMap
2apiVersion: v1
3kind: ConfigMap
4metadata:
5  name: app-config
6data:
7  APP_ENV: production
8  LOG_LEVEL: info
9
10---
11# Secret
12apiVersion: v1
13kind: Secret
14metadata:
15  name: app-secrets
16type: Opaque
17data:
18  DATABASE_URL: cG9zdGdyZXM6Ly91c2VyOnBhc3NAaG9zdC9kYg==

#Helm

bash
1# Install Helm
2curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
3
4# Add repo
5helm repo add bitnami https://charts.bitnami.com/bitnami
6
7# Install chart
8helm install my-postgres bitnami/postgresql
9
10# List releases
11helm list
12
13# Upgrade
14helm upgrade my-postgres bitnami/postgresql --set auth.postgresPassword=newpass

[!TIP] Pro Tip: Use Helm for managing complex deployments!