Kubernetes – Connect To Private Container Registry

Kubernetes Logo

Now that you are hosting your own registry (… are you?). You probably want to deploy Kubernetes pods from that registry. For this you need two things:

  1. Docker registry credentials saved in a Secret
  2. imagePullSecrets in deployment pointing to said Secret

First, Create secret:

~$ kubectl create secret docker-registry <SECRET_NAME> --docker-server=<REGISTRY_SERVER>--docker-username=<REGISTRY_USERNAME> --docker-password=<REGISTRY_PASSWORD> --docker-email=<REGISTRY_EMAIL>

Second, Use secret in in deployment. Example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: l33t
spec:
  replicas: 1
  selector:
    matchLabels:
      app: l33t
  template:
    metadata:
      labels:
        app: l33t
    spec:
      containers:
        - name: <CONTAINER_NAME>
          image: dockerreg.tld/<CONTAINER_NAME>:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 1337
      imagePullSecrets:
        - name: <SECRET_NAME>

And you’re done 🍔

Leave a Reply

Your email address will not be published. Required fields are marked *