I have one of my images private and was getting access with the imagePullSecrets: up until now but after enabling 2FA for docker-hub Kubernetes can no longer pull my image, how do I solve this?
currently using: apiVersion: apps/v1 kind: Deployment
CodePudding user response:
You need to create a new imagePullSecret and use it in your manifests.
Login with your username and personal access token. this will update your ~/.docker/config.json
docker login registry.example.com -u <your_username> -p <your_personal_access_token>
Create your imagePullSecret using the updated config.json
kubectl create secret generic regcred \
--from-file=.dockerconfigjson=<path/to/.docker/config.json> \
--type=kubernetes.io/dockerconfigjson
Update your deployment,statefulset,pod,jobs to use this new secret
Alternatively, if you want to make this imagePullSecret default for a namespace. Just make sure that the secret exists in that namespace. Secret may have same name in multiple namespaces as it is a namespaced object.
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "regcred"}]}'
