Your cart is currently empty!
Kubernetes: Pulling Image From Private Registry
Create the Secret for you docker registry:
Shell
x
2
1
kubectl create secret docker-registry NAME --docker-username=user --docker-password=password --docker-email=email
2
[--docker-server=string] [--from-file=[key=]source] [--dry-run=server|client|none] [options]
To double check:
Shell
1
1
1
kubectl get secret NAME --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode
Create a test pod:
Shell
1
1
1
kubectl run NAME --image REGISTRY-SERVER/REPOSITORY/IMAGE:TAG --overrides '{ "spec": { "imagePullSecrets" : [{"name": "REGISTRY-SECRET-NAME" }] }}'
For pod, setting the imagePullSecrets only available using the –overrides flag when you create the pod. After the pod is created, you cannot edit the imagePullSecrets using kubectl edit or patch.
DEPLOYMENT
You can edit the deployment manifest and add the following at line 9, 10:
YAML
1
10
10
1
apiVersion apps/v1
2
kind Deployment
3
metadata...
4
spec
5
template
6
spec
7
containers
8
...
9
imagePullSecrets
10
name <secret-name>
Or you can always kubectl patch
. Use flag --type strategic
(default) to append or --type merge
to replace.
Shell
1
1
1
kubectl patch deployment <name> --type merge -p '{ "spec": { "template": { "spec": { "imagePullSecrets": [{ "name": "<secret-name>" }] } } } }'
SERVICE ACCOUNT
The easiest way to attach the imagePullSecrets is in your ServiceAccount:
YAML
1
6
1
apiVersion v1
2
kind ServiceAccount
3
imagePullSecrets
4
name <secret-name>
5
metadata
6
...
REFERENCES:
Leave a Reply