You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2023/day39.md
+45-3Lines changed: 45 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,17 +136,35 @@ We must now exec into our vault-0 pod to enable the secret engine.
136
136
137
137
`vault secrets enable -path=secret kv-v2`
138
138
139
+
## Creating a new secret for our app
139
140
140
-
`vault kv put secret/devwebapp/config username='giraffe' password='salsa'`
141
+
As a simple test we want to create an application in its own namespace within our Kubernetes cluster to then communicate with vault in its own namespace.
142
+
143
+
This is one thing that is not defined in the tutorial linked, and I wanted to provide a bit more real life use case because yes the default namespace can be used but that doesn't mean it should be.
144
+
145
+
`vault kv put secret/devwebapp/config username='90DaysOfDevOps' password='90DaysOfDevOps'`
146
+
147
+
We can confirm what we have just created with the following command:
141
148
142
149
`vault kv get secret/devwebapp/config`
143
150
151
+
You can see the above commands ran in my terminal below.
152
+
153
+

154
+
155
+
Next we need to enable the Kubernetes authentication method.
156
+
144
157
`vault auth enable kubernetes`
145
158
159
+
Configure the Kubernetes authentication method to use the location of the Kubernetes API.
Create a Kubernetes authentication role named devweb-app, this has been taken from the tutorial from Hashicorp but notice that we define a namespace other than default.
177
+
158
178
```
159
179
vault write auth/kubernetes/role/devweb-app \
160
180
bound_service_account_names=internal-app \
161
-
bound_service_account_namespaces=default \
181
+
bound_service_account_namespaces=webdevapp \
162
182
policies=devwebapp \
163
183
ttl=24h
164
184
```
185
+
Now we can exit our vault-0 pod.
165
186
166
187
`exit`
167
188
168
-
`kubectl create ns webdevapp`
189
+
## Deploying our Application
190
+
191
+
As mentioned now back into our Kubernetes cluster, it is time to create and deploy our application to complete this demo.
192
+
193
+
Firstly, create the application namespace with
194
+
195
+
`kubectl create ns devwebapp`
196
+
197
+
We will now create our serviceaccount.
169
198
170
199
`kubectl create sa internal-app -n devwebapp`
171
200
201
+
Now for our application, we will create the following yaml file and you will find this in the day39 folder.
202
+
172
203
```
173
204
cat > devwebapp.yaml <<EOF
174
205
---
@@ -189,9 +220,20 @@ spec:
189
220
image: jweissig/app:0.0.1
190
221
EOF
191
222
```
223
+
We will be deploying this to our newly created namespace with the following command.
224
+
192
225
`kubectl create -f devwebapp.yaml -n devwebapp`
193
226
227
+
Check the status of the pods.
228
+
194
229
`kubectl get pods -n devwebapp`
195
230
231
+
Finally we can confirm that we have the correct credentials stored in our app.
0 commit comments