Accessing Private Docker Images From Kubernetes

- By Manisha Sahasrabudhe on June 18, 2018

Most organizations store proprietary Docker images in private registries. While it is easy to deploy public Docker images to Kubernetes, there are some additional steps involved when you're dealing with private images. This tutorial shows you how to configure a Kubernetes cluster to access those private images. 

The tutorial assumes that you have working knowledge of Docker and Kubernetes and understand the following concepts:

* Docker Getting Started
* Docker Registry 
* Kubernetes basics
* kubectl command
* ImagePullSecrets concept

 

Instructions

In this tutorial, we will use ImagePullSecrets which is a type of secret that allows you to pull from private Docker registries. 

 

1. Connect to your cluster using kubectl

Make sure you are authenticated to your cluster with kubectl. For a self hosted Kubernetes, authentication options are explained in the Kubernetes docs

 

2. Create an ImagePullSecret

We will leverage kubectl create secret command to create a docker-registry secret. Run this command to create a secret named myRegSecret on the cluster:

kubectl create secret docker-registry myRegSecret --docker-username="<username>" --docker-password="<password>" --docker-server="<server url>" --docker-email="<email>"

Replace username, password, url and email to match your account.

 

3. Using imagePullSecrets in a Deploy Spec

In your application deployment spec, add the ImagePullSecrets section to pull from your private registry:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
namespace: default
name: ${APP_LABEL}
spec:
replicas: 1
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: ${APP_LABEL}
spec:
imagePullSecrets:
- name: myRegSecret
containers:
- name: ${APP_LABEL}
image: ${APP_IMG}:${APP_TAG}
ports:
- containerPort: 80
resources:
requests:
cpu: 250m
limits:
cpu: 500m

Make sure you replace the wildcards `${APP_LABEL}`, `${APP_IMG}` and `${APP_TAG}` in the file with information that applies to your scenario.

That's all you need to deploy private images to Kubernetes. To automate deployments, check out our tutorial on Automating deployments to a self-hosted Kubernetes cluster.

Topics: Docker, Kubernetes, Private Docker Registry


Add comments below...