DEV Community

Ayush Kumar
Ayush Kumar

Posted on

Deploy a K8S Pod with a Private Docker Image

To boot up a pod with a private image in Kubernetes, you've got the basic steps down, but let's walk through the process in a bit more detail.

1. Create a Secret for Docker Registry Authentication

kubectl create secret docker-registry <secret-name> \
  --docker-server=<registry-url> \
  --docker-username=<your-username> \
  --docker-password=<your-password> \
  --docker-email=<your-email>
Enter fullscreen mode Exit fullscreen mode
  • : Name of the secret you're creating.
  • : URL of your Docker registry (e.g., https://index.docker.io/v1/ for Docker Hub).
  • : Your Docker registry username.
  • : Your Docker registry password.
  • : Your Docker registry email.

2. Reference the Secret in Your Pod Configuration

Once the secret is created, you need to reference it in your pod's YAML configuration under the imagePullSecrets field.
Here is an example of how to structure your pod YAML:

apiVersion: v1
kind: Pod
metadata:
  name: my-private-image-pod
spec:
  containers:
  - name: my-container
    image: <registry-url>/<image-name>:<tag>
    # Example: image: myregistry.azurecr.io/myimage:1.0
  imagePullSecrets:
  - name: <secret-name>
Enter fullscreen mode Exit fullscreen mode
  • /:: Your private image's full path in the registry, including the tag.
  • : The name of the secret you created earlier.

3. Deploy the Pod
Finally, apply the YAML configuration to your Kubernetes cluster:

kubectl apply -f <pod-config.yaml>
Enter fullscreen mode Exit fullscreen mode

With these steps, your pod should successfully pull the private image from the specified Docker registry.

Top comments (0)