Accessing Private Docker Images From Kubernetes

DZone 's Guide to

Accessing Private Docker Images From Kubernetes

This tutorial will show you how to access stored proprietary and private Docker images using Kubernetes.

· Cloud Zone ·
Free Resource

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 a working knowledge of Docker and Kubernetes and understand the following concepts:


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
namespace: default
name: ${APP_LABEL}
replicas: 1
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
app: ${APP_LABEL}
- name: myRegSecret
- name: ${APP_LABEL}
image: ${APP_IMG}:${APP_TAG}
- containerPort: 80
cpu: 250m
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.

cloud, deployment, docker, kubernetes, private image

Published at DZone with permission of Manisha Sahasrabudhe , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}