Skip to content

Commit c260992

Browse files
authored
Merge pull request #21043 from scoulomb/imgPullSecSa
Task configure sa: 'Add image pull secrets to a service account' sect…
2 parents 1e94e95 + 9ea75a8 commit c260992

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

content/en/docs/tasks/configure-pod-container/configure-service-account.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,38 @@ The content of `token` is elided here.
183183

184184
## Add ImagePullSecrets to a service account
185185

186-
First, create an imagePullSecret, as described [here](/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod).
187-
Next, verify it has been created. For example:
186+
### Create an imagePullSecret
188187

189-
```shell
190-
kubectl get secrets myregistrykey
191-
```
188+
- Create an imagePullSecret, as described in [Specifying ImagePullSecrets on a Pod](/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod).
192189

193-
The output is similar to this:
190+
```shell
191+
kubectl create secret docker-registry myregistrykey --docker-server=DUMMY_SERVER \
192+
--docker-username=DUMMY_USERNAME --docker-password=DUMMY_DOCKER_PASSWORD \
193+
--docker-email=DUMMY_DOCKER_EMAIL
194+
```
194195

195-
```
196-
NAME TYPE DATA AGE
197-
myregistrykey   kubernetes.io/.dockerconfigjson   1       1d
198-
```
196+
- Verify it has been created.
197+
```shell
198+
kubectl get secrets myregistrykey
199+
```
200+
201+
The output is similar to this:
202+
203+
```
204+
NAME TYPE DATA AGE
205+
myregistrykey   kubernetes.io/.dockerconfigjson   1       1d
206+
```
207+
208+
### Add image pull secret to service account
199209

200210
Next, modify the default service account for the namespace to use this secret as an imagePullSecret.
201211

212+
202213
```shell
203214
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "myregistrykey"}]}'
204215
```
205216

206-
Interactive version requires manual edit:
217+
You can instead use `kubectl edit`, or manually edit the YAML manifests as shown below:
207218

208219
```shell
209220
kubectl get serviceaccounts default -o yaml > ./sa.yaml
@@ -248,12 +259,19 @@ Finally replace the serviceaccount with the new updated `sa.yaml` file
248259
kubectl replace serviceaccount default -f ./sa.yaml
249260
```
250261

251-
Now, any new pods created in the current namespace will have this added to their spec:
262+
### Verify imagePullSecrets was added to pod spec
252263

253-
```yaml
254-
spec:
255-
imagePullSecrets:
256-
- name: myregistrykey
264+
Now, when a new Pod is created in the current namespace and using the default ServiceAccount, the new Pod has its `spec.imagePullSecrets` field set automatically:
265+
266+
````shell
267+
kubectl run nginx --image=nginx --restart=Never
268+
kubectl get pod nginx -o=jsonpath='{.spec.imagePullSecrets[0].name}'
269+
````
270+
271+
The output is:
272+
273+
```shell
274+
myregistrykey
257275
```
258276

259277
<!--## Adding Secrets to a service account.

0 commit comments

Comments
 (0)