|
| 1 | + |
| 2 | +************************************************************************************************************************************************* |
| 3 | +. |
| 4 | +. Demo: ConfigMaps | Raman Sharma |
| 5 | +. |
| 6 | +************************************************************************************************************************************************* |
| 7 | +First Check no pods and no configMaps are available( kubectl get configmaps) |
| 8 | +Overview: |
| 9 | +--------- |
| 10 | +1. Creating Configmap from "multiple files" & Consuming it inside Pod from "volumes" |
| 11 | + |
| 12 | + 1a. Create Configmap "nginx-configmap-vol" from "multiple files" |
| 13 | + 1b. Consume "nginx-configmap-vol" configmap inside Pod from "volumes" |
| 14 | + 1c. Create | Display | Validate |
| 15 | + |
| 16 | +2. Creating Configmap from "literal values" & Consuming it inside Pod from "environment variables" |
| 17 | + |
| 18 | + 2a. Create configmap �redis-configmap-env� from "literal values" |
| 19 | + 2b. Consume �redis-configmap-env� configmap inside pod from �Environment Variables� inside pod |
| 20 | + 2c. Create | Display | Validate |
| 21 | + |
| 22 | +3. Cleanup |
| 23 | + |
| 24 | + 3a. Delete configmaps |
| 25 | + 3b. Delete pods |
| 26 | + 3c. Validate |
| 27 | + |
| 28 | +************************************************************************************************************************************************* |
| 29 | + |
| 30 | +1. Creating Configmap from "multiple files" & Consuming it inside Pod from "volumes" |
| 31 | + |
| 32 | + |
| 33 | +1a. Create Configmap "nginx-configmap-vol" from "multiple files": |
| 34 | +------------------------------------------------------------------ |
| 35 | +echo -n 'Non-sensitive data inside file-1' > file-1.txt |
| 36 | +echo -n 'Non-sensitive data inside file-2' > file-2.txt |
| 37 | + |
| 38 | +kubectl create configmap nginx-configmap-vol --from-file=file-1.txt --from-file=file-2.txt |
| 39 | +# rm -f file-1 file-2 |
| 40 | + |
| 41 | +kubectl get configmaps |
| 42 | +kubectl get configmaps nginx-configmap-vol -o yaml |
| 43 | +kubectl describe configmaps nginx-configmap-vol |
| 44 | + |
| 45 | +========================================================== |
| 46 | + |
| 47 | +1b. Consume above "nginx-configmap-vol" configmap inside Pod from "volumes" |
| 48 | +--------------------------------------------------------------------------- |
| 49 | + |
| 50 | +#nginx-pod-configmap-vol.yaml |
| 51 | +apiVersion: v1 |
| 52 | +kind: Pod |
| 53 | +metadata: |
| 54 | + name: nginx-pod-configmap-vol |
| 55 | +spec: |
| 56 | + containers: |
| 57 | + - name: nginx-container |
| 58 | + image: nginx |
| 59 | + volumeMounts: |
| 60 | + - name: test-vol |
| 61 | + mountPath: "/etc/non-sensitive-data" |
| 62 | + readOnly: true |
| 63 | + volumes: |
| 64 | + - name: test-vol |
| 65 | + configMap: |
| 66 | + name: nginx-configmap-vol |
| 67 | + items: |
| 68 | + - key: file-1.txt |
| 69 | + path: file-a.txt |
| 70 | + - key: file-2.txt |
| 71 | + path: file-b.txt |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +========================================================== |
| 76 | + |
| 77 | +1c. Create | Display | Validate: |
| 78 | +-------------------------------- |
| 79 | + |
| 80 | +# Create |
| 81 | +kubectl create -f nginx-pod-configmap-vol.yaml |
| 82 | + |
| 83 | +# Display |
| 84 | +kubectl get po |
| 85 | +kubectl get configmaps |
| 86 | +kubectl describe pod nginx-pod-configmap-vol |
| 87 | + |
| 88 | +# Validate from "inside" the pod |
| 89 | +kubectl exec nginx-pod-configmap-vol -it /bin/sh |
| 90 | +cd /etc/non-sensitive-data |
| 91 | +ls |
| 92 | +cat Non-sensitive data inside file-1.txt |
| 93 | +cat password.txt |
| 94 | +exit |
| 95 | + |
| 96 | +(OR) |
| 97 | + |
| 98 | +# Validate from "outside" the pod |
| 99 | +kubectl exec nginx-pod-configmap-vol ls /etc/non-sensitive-data |
| 100 | +kubectl exec nginx-pod-configmap-vol cat /etc/non-sensitive-data/file-a.txt |
| 101 | +kubectl exec nginx-pod-configmap-vol cat /etc/non-sensitive-data/file-b.txt |
| 102 | + |
| 103 | + |
| 104 | +************************************************************************************************************************************************* |
| 105 | + |
| 106 | +2. Creating Configmap from "literal values" & Consuming it inside Pod from "environment variables" |
| 107 | + |
| 108 | + |
| 109 | +2a. Create configmap �redis-configmap-env� from "literal values" |
| 110 | +----------------------------------------------------------------- |
| 111 | + |
| 112 | +kubectl create configmap redis-configmap-env --from-literal=file.1=file.a --from-literal=file.2=file.b |
| 113 | + |
| 114 | +kubectl get configmap |
| 115 | +kubectl describe configmap redis-configmap-env |
| 116 | + |
| 117 | +=============================================================================== |
| 118 | + |
| 119 | +2b. Consume �redis-configmap-env� configmap inside pod from �Environment Variables� inside pod |
| 120 | +----------------------------------------------------------------------------------------------- |
| 121 | + |
| 122 | +# redis-pod-configmap-env.yaml |
| 123 | +apiVersion: v1 |
| 124 | +kind: Pod |
| 125 | +metadata: |
| 126 | + name: redis-pod-configmap-env |
| 127 | +spec: |
| 128 | + containers: |
| 129 | + - name: redis-container |
| 130 | + image: redis |
| 131 | + env: |
| 132 | + - name: FILE_1 |
| 133 | + valueFrom: |
| 134 | + configMapKeyRef: |
| 135 | + name: redis-configmap-env |
| 136 | + key: file.1 |
| 137 | + - name: FILE_2 |
| 138 | + valueFrom: |
| 139 | + configMapKeyRef: |
| 140 | + name: redis-configmap-env |
| 141 | + key: file.2 |
| 142 | + restartPolicy: Never |
| 143 | + |
| 144 | +=============================================================================== |
| 145 | + |
| 146 | +2c. Create | Display | Validate: |
| 147 | + |
| 148 | +# Create |
| 149 | +kubectl create -f redis-pod-configmap-env.yaml |
| 150 | + |
| 151 | +# Display |
| 152 | +kubectl get pods |
| 153 | +kubectl get configmaps |
| 154 | +kubectl describe pod redis-pod-configmap-env |
| 155 | + |
| 156 | + |
| 157 | +# Validate from "inside" the pod |
| 158 | +kubectl exec redis-pod-configmap-env -it /bin/sh |
| 159 | +env | grep FILE |
| 160 | +exit |
| 161 | + |
| 162 | +(OR) |
| 163 | + |
| 164 | +# Validate from "outside" the pod |
| 165 | +kubectl exec redis-pod-configmap-env env | grep FILE |
| 166 | + |
| 167 | + |
| 168 | +************************************************************************************************************************************************* |
| 169 | + |
| 170 | +3. Cleanup |
| 171 | + |
| 172 | +# Delete configmaps |
| 173 | +kubectl delete configmaps nginx-configmap-vol redis-configmap-env |
| 174 | + |
| 175 | +# Delete pods |
| 176 | +kubectl delete pods nginx-pod-configmap-vol redis-pod-configmap-env |
| 177 | + |
| 178 | +# Validate |
| 179 | +kubectl get pods |
| 180 | +kubectl get configmaps |
| 181 | + |
| 182 | + |
| 183 | +************************************************************************************************************************************************* |
| 184 | + |
| 185 | + |
0 commit comments