-
Notifications
You must be signed in to change notification settings - Fork 56
/
5.++Secrets.txt
100 lines (71 loc) · 2.54 KB
/
5.++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
*************************************************************************************************************************************************
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. Cleanup
2a. Delete secrets
2b. Delete pods
2c. 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 nginx-pod-secret-vol
# 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. Cleanup
# Delete secrets
kubectl delete secrets nginx-secret-vol
# Delete pods
kubectl delete pods nginx-pod-secret-vol
# Validate
kubectl get pods
kubectl get secrets
*************************************************************************************************************************************************