-
Notifications
You must be signed in to change notification settings - Fork 26
/
Day-3-Secrets.txt
192 lines (139 loc) · 4.85 KB
/
Day-3-Secrets.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
*************************************************************************************************************************************************
.
. Demo: Secrets | Srinath Challa
.
*************************************************************************************************************************************************
Overview:
---------
1. Create Secret using "kubectl" & Consuming it from "volumes" inside Pod
1a. Create secret "nginx-secret-vol" using "Kubectl"
1b. Consume "nginx-secret-vol" from "volumes" inside Pod
1c. Create | Display | Validate
2. Create Secret "manually" using YAML file & Consuming it from "environment variables" inside Pod
2a. Create secret ìredis-secret-envî using YAML file:
2b. Consume ìredis-secret-envî secret from ìEnvironment Variablesî inside pod
2c. Create | Display | Validate
3. Cleanup
3a. Delete secrets
3b. Delete pods
3c. Validate
*************************************************************************************************************************************************
# 1. Creating Secret using Kubectl & Consuming it from "volumes" inside Pod
1a. Creating secret using "Kubectl":
------------------------------------
echo -n 'admin' > username.txt
echo -n 'pa$$w00rd' > password.txt
kubectl create secret generic nginx-secret-vol --from-file=username.txt --from-file=password.txt
# rm -f username.txt password.txt
kubectl get secrets
kubectl describe secrets nginx-secret-vol
==========================================================
1b. Consuming "nginx-secret-vol" from "volumes" inside Pod
--------------------------------------------------------
#nginx-pod-secret-vol.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod-secret-vol
spec:
containers:
- name: nginx-container
image: nginx
volumeMounts:
- name: test-vol
mountPath: "/etc/confidential"
readOnly: true
volumes:
- name: test-vol
secret:
secretName: nginx-secret-vol
==========================================================
1c. Create | Display | Validate:
--------------------------------
# Create
kubectl create -f nginx-pod-secret-vol.yaml
# Display
kubectl get po
kubectl get secrets
kubectl describe pod
# Validate from "inside" the pod
kubectl exec nginx-pod-secret-vol -it /bin/sh
cd /etc/confidential
ls
cat username.txt
cat password.txt
exit
(OR)
# Validate from "outside" the pod
kubectl exec nginx-pod-secret-vol ls /etc/confidential
kubectl exec nginx-pod-secret-vol cat /etc/confidential/username.txt
kubectl exec nginx-pod-secret-vol cat /etc/confidential/password.txt
*************************************************************************************************************************************************
2. Creating Secret "manually" using YAML file & Consuming it from "environment variables" inside Pod
2a. Creating Secret using YAML file:
-------------------------------------
# Encoding secret
echo -n 'admin' | base64
echo -n 'pa$$w00rd' | base64
# YAML file
# redis-secret-env.yaml
apiVersion: v1
kind: Secret
metadata:
name: redis-secret-env
type: Opaque
data:
username: YWRtaW4=
password: cGEkJHcwMHJk
kubectl create -f redis-secret-env.yaml
kubectl get secret
kubectl describe secret redis-secret-env
===============================================================================
2b. Consuming ìredis-secret-envî secret from ìEnvironment Variablesî inside pod
--------------------------------------------------------------------------------
# redis-pod-secret-env.yaml
apiVersion: v1
kind: Pod
metadata:
name: redis-pod-secret-env
spec:
containers:
- name: redis-container
image: redis
env:
- name: SECRET_USERNAME
valueFrom:
secretKeyRef:
name: redis-secret-env
key: username
- name: SECRET_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret-env
key: password
restartPolicy: Never
===============================================================================
2c. Create | Display | Validate:
# Create
kubectl create -f redis-pod-secret-env.yaml
# Display
kubectl get pods
kubectl get secrets
kubectl describe pod redis-pod-secret-env
# Validate from "inside" the pod
kubectl exec redis-pod-secret-env -it /bin/sh
env | grep SECRET
exit
(OR)
# Validate from "outside" the pod
kubectl exec redis-pod-secret-env env | grep SECRET
*************************************************************************************************************************************************
3. Cleanup
# Delete secrets
kubectl delete secrets nginx-secret-vol redis-secret-env
# Delete pods
kubectl delete pods nginx-pod-secret-vol redis-pod-secret-env
# Validate
kubectl get pods
kubectl get secrets
*************************************************************************************************************************************************