VIX-Chevron-Up

How To Get Kubernetes Pulling From a Private Gitlab Container Registry

By Tony Yates

At VIX Digital we use cloud hosted gitlab for certain functions and one of those is as a container registry, it is free, takes a second to setup and performs well for most things. It isn't our only place for storing container images, but the same applies.

Kubernetes will pull images from wherever you specify but will need to know any access credentials required if not in the public domain. Here is how it is done:

kubectl create secret docker-registry gitlab-auth \
--docker-server=https://registry.gitlab.com \
--docker-username=xxxxxx \
--docker-password=xxxxxxx \
--docker-email=xxxxxxx

This secret will be stored in the kubernetes etcd cluster and accessible by worker nodes.

Be sure to add imagePullSecrets to your deployment yaml file.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nifty-little-apps
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nifty-little-apps
    spec:
      containers:
      - name: nifty-little-app
        image: registry.gitlab.com/vix/registry/nifty-little-app:1.0.0
        ports:
        - containerPort: 8000
          protocol: TCP
      imagePullSecrets:
      - name: gitlab-auth
---
        apiVersion: v1
        kind: Service
        metadata:
          name: nifty-little-svc
        spec:
          ports:
          - port: 80
            targetPort: 8000
            protocol: TCP
            name: http
          selector:
            app: nifty-little-apps
<< Back to Insights