k8s deploymet with image from private registry

7/21/2020

I've k8s deployment yaml which I need to pull image from private registry where should I put the

host 
user 
password 

deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tra
  namespace: ba
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tra
  template:
    metadata:
      labels:
        app: tra
    spec:
      containers:
        - name: tra
          image: de/sec:0.0.10
          imagePullPolicy: Always
          ports:
            - containerPort: 5000

I found this but it doesnt really helps

https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

-- NSS
azure
docker
kubernetes

1 Answer

7/21/2020

The doc contains detailed about pulling secrets from private registry.

Summary is, 1. Create secret using following command

kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
  1. Than specify the secret name in your deployment file by adding following line
imagePullSecrets:
  - name: regcred

So, Create a secret and modify your deployment like

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tra
  namespace: ba
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tra
  template:
    metadata:
      labels:
        app: tra
    spec:
      containers:
        - name: tra
          image: de/sec:0.0.10
          imagePullPolicy: Always
          ports:
            - containerPort: 5000
      imagePullSecrets:
        - name: regcred

If you want to create secret from file then update following file into secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name: regcred
  namespace: <namespace>
data:
  .dockerconfigjson: < add here output of cat ~/.docker/config.json| base64 -w 0 >
type: kubernetes.io/dockerconfigjson

then run kubectl apply -f secret.yaml

-- hoque
Source: StackOverflow