Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

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:

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.

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Topics:
deployment ,kubernetes ,docker ,private image ,cloud

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}