Kubernetes Deployment with ConfigMap example

This config will use the ConfigMap defined in the previous post.

The deployment YAML:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:1.12
        name: nginx
        ports:
        - containerPort: 80
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 80
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 80
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
          initialDelaySeconds: 10
        resources:
          requests:
            cpu: 50m
            memory: 100Mi
          limits:
            cpu: 100m
            memory: 100Mi
        volumeMounts:
        - name: config
          mountPath: /etc/nginx/conf.d/
      volumes:
      - name: config
        configMap:
	  name: my-configmap
Apply it:
kubectl apply -f deploymentwithconfigmap.yaml
You should get the same config like in previous defined article (link above).

Test. Go into one of pods and check nginx config:
kubectl exec -it my-deployment-76f6f96875-w8dw5 bash
root@my-deployment-76f6f96875-w8dw5:/# cd /etc/nginx/conf.d/
root@my-deployment-76f6f96875-w8dw5:/etc/nginx/conf.d# cat default.conf