Image Pull Secrets in Kubernetes

Image Pull Secrets in Kubernetes

Learn how Kubernetes proves its identity to a private image registry, how pull secrets are created, attached, refreshed, and protected, and how to fix the dreaded ImagePullBackOff error, from first principles to production habits.

Imagine a members-only library. Anyone may walk past the front desk, but only members can borrow books, and the librarian asks to see a card before handing anything over. If you forget your card, the librarian politely refuses, and you go home with nothing, however much you need the book.

A private image registry is that library, and your cluster is the person who wants to borrow. The books are container images, the programs your applications run from. The membership card is a small piece of secret information called an image pull secret. This tutorial explains, from the ground up, what that secret contains, how Kubernetes uses it, where it can go wrong, and how to handle it safely in a real production cluster.

1Why Pull Secrets Exist

Most real companies keep their application images private. Kubernetes must therefore prove who it is before it can download them.

Where images live

An image is a packaged copy of a program together with everything it needs to run. Before Kubernetes can start a container, it must fetch that image from a place that stores images. That place is called a container registry. Some registries are public, like a public noticeboard: anyone can read. Many are private, like a company filing cabinet: only approved people or programs may open it.

Your company’s own applications almost always sit in a private registry. The images may contain business logic, internal tools, or code that competitors would love to see. Public access would be a serious risk, so the registry asks every visitor for credentials, meaning a username and a password or token, before it hands over an image.

Simple Analogy

Think of a warehouse that stores your company’s goods. The gate guard will release a crate only to a driver who shows the right pass. A Kubernetes machine is the driver, an image is the crate, and the image pull secret is the pass.

The problem Kubernetes must solve

In a cluster, nobody sits at a keyboard typing a password each time a container starts. Pods are created automatically, on any machine, at any hour, sometimes hundreds at once. Kubernetes needs a way to hold the credentials safely and hand them to the right machine at the right moment, without putting them inside the image or the application code.

The answer is a Kubernetes object called a Secret, of a special type meant for registry logins. A pod description points to it, and Kubernetes passes it to the machine that will pull the image.

Private
registries require a login before an image can be pulled
Secret
the Kubernetes object that holds the login
Kubelet
the machine agent that actually pulls the image

What happens without it

If a pod asks for an image from a private registry and no valid credentials are available, the pull fails. The pod stays stuck, and its status shows messages such as ErrImagePull, and then ImagePullBackOff. Almost every Kubernetes user meets these messages sooner or later. Understanding pull secrets turns them from a mystery into a five-minute fix.

i
Not every registry needs a secret

Public images, such as many open source ones, need no credentials. Some clusters also get credentials automatically from their cloud provider. We cover those options later. A pull secret is needed when the registry is private and nothing else supplies the login.

2The Core Idea: Who Pulls, and With Whose Card

Four characters appear in every image pull: the registry, the pod description, the secret, and the kubelet. Once you know their roles, everything else is detail.

The four characters

Character 1

Registry

The server that stores images and checks logins before letting anyone download them.

Character 2

Pod description

The instructions that say which image to run and which secrets may be used to pull it.

Character 3

Image pull secret

A Secret object holding the registry address, the username, and the password or token.

Character 4

Kubelet

The agent on each machine that starts pods. It reads the secret and uses it to download the image.

flowchart LR
    POD["Pod description: image name and secret name"] --> KL["Kubelet on the machine"]
    SEC["Image pull secret in the cluster"] --> KL
    KL -->|"presents login"| REG["Private registry"]
    REG -->|"sends image layers"| KL
    KL --> RUN["Container starts"]
        
FIG 1 — The kubelet combines the pod’s instructions with the secret, and pulls the image from the registry

Read the figure from left to right. The pod description says what to run and which secret to use. The kubelet reads both, then goes to the private registry and presents the login. If the registry accepts it, the image is sent back in pieces, and the container can start.

Simple Analogy

Picture a delivery driver with a work order and a pass. The work order, the pod description, says which crate to collect. The pass, the secret, proves the driver may collect it. The warehouse, the registry, checks the pass and loads the crate. Without either paper, the driver returns empty-handed.

Important: the machine does the pulling

Many people imagine the pod itself downloads its image. In truth, the pod does not exist yet. The kubelet, which runs on the machine, pulls the image before the pod’s containers start, using the underlying container runtime, which is the software that actually runs containers. This is why the secret must be given to the kubelet, and why the credentials are not visible to the application inside the pod.

!
A pull secret is not an application password

The pull secret is used by the machine to fetch images. It is not the same as passwords that your application uses to reach a database or another service. Keep them separate and never reuse one for the other.

3Background You Need First

A few small ideas will make the rest of the tutorial simple. Each is explained in everyday words.

What an image name means

An image name has parts. First comes the registry address, such as the web name of the registry. Then a path, which often includes the team or project. Then the image name itself, and finally a tag or a digest. A tag is a friendly label, such as a version number. A digest is a long fingerprint that points to one exact image and never changes. If no registry address is written, Kubernetes assumes a default public registry.

Simple Analogy

An image name is like a postal address. The registry is the city, the path is the street, the image name is the house, and the tag is the flat number. The digest is like a unique GPS location that never moves.

Pods, nodes, and the kubelet

A pod is the smallest thing Kubernetes runs. A node is a computer, real or virtual, that runs pods. The kubelet is the agent on each node that receives instructions from the control part of the cluster and makes them real, including pulling images.

Namespaces

A namespace is a named area inside the cluster that groups related things. Many objects, including Secrets, belong to one namespace and can only be used by pods in that same namespace. This has a big consequence for pull secrets, which we will meet again: a secret in one namespace cannot be used by a pod in another.

Secrets, and what base64 really is

A Secret is a Kubernetes object designed to hold small pieces of sensitive information, such as passwords. Its values are stored in a form called base64. Base64 is only a way of writing data using letters and numbers. It is not encryption. Anyone can turn it back into the original text in a second. This is why access to Secrets must be carefully controlled, which we cover in the security chapter.

Service accounts

A service account is an identity that pods use inside the cluster. Every namespace has a default one, and each pod runs as some service account. A service account can also carry a list of image pull secrets, and any pod using that account will automatically get them. This is a very handy shortcut.

Word 1

Registry

A server that stores and serves images.

Word 2

Tag and digest

A friendly label for a version, and an exact unchangeable fingerprint.

Word 3

Kubelet

The agent on each node that starts pods and pulls images.

Word 4

Namespace

A named area of the cluster. Secrets stay inside their own namespace.

Word 5

Secret

An object that holds sensitive values. Encoded, not encrypted, by default.

Word 6

Service account

An identity for pods, which can carry pull secrets for all its pods.

The image pull policy

Each container also has an image pull policy, which says when Kubernetes should pull. With one choice, the image is pulled every time a container starts. With another, it is pulled only if the machine does not already have it. With a third, it is never pulled, and the image must already be on the machine. This policy matters, because a pull secret is only needed when a pull is actually attempted.

PolicyMeaningNeeds a secret?
AlwaysCheck the registry every time a container startsYes, every time
IfNotPresentPull only if the image is not already on the machineOnly for the first pull on each machine
NeverNever pull; the image must already be thereNo

4Anatomy of an Image Pull Secret

An image pull secret is an ordinary Secret with a special type and a special shape. Knowing what is inside makes mistakes easy to spot.

The type and the key

Secrets have types, which tell Kubernetes what kind of information they hold. The type for registry logins is named kubernetes.io/dockerconfigjson. A Secret of this type must contain one entry, with the key named .dockerconfigjson. The value of that entry is a small piece of structured text in a format originally invented for Docker’s own login file.

What the text contains

Inside that text is a list of registries. For each registry, there is the address, and the credentials for it. The credentials appear as a username, a password or token, and often a combined field called auth, which is the username and password joined together and written in base64. The registry address in the secret must match the registry in the image name, otherwise Kubernetes will not use the secret for that image.

PartWhat it holdsCommon mistake
Secret typekubernetes.io/dockerconfigjsonCreating a generic Secret instead, which Kubernetes will not use for pulling
Key name.dockerconfigjsonMisspelling it, or omitting the leading dot
Registry addressThe server that matches the image nameUsing a different address, such as a web page URL instead of the registry server
UsernameThe account name, or a fixed word for token-based loginsUsing a personal account that may be removed later
Password or tokenThe secret value used to log inUsing a password that expires soon
Auth fieldUsername and password joined and encodedEncoding it by hand with a stray newline at the end
Simple Analogy

Think of a key ring in a caretaker’s office. Each key has a tag showing which building it opens. If the tag is wrong or missing, the caretaker cannot tell which key belongs to which door. The registry address inside the secret is the tag.

Ways to create one

There are several ways to make the secret. The most common uses the command line tool: you ask it to create a docker-registry Secret, and give it a name, the registry address, a username, and a password. The tool builds the correct structure for you. Another way is to point the tool at an existing Docker login file on your computer and let it copy the contents. A third is to write the full description as a file and apply it, which is popular in automated pipelines. A fourth is to let a controller or operator create and refresh the secret for you.

Method 1

From command-line values

Simple and quick. The tool builds the right structure. Careful: the password may remain in your shell history.

Method 2

From an existing login file

Copies what your local Docker login already holds. Watch out for logins that use a system keychain instead of storing the credentials in the file.

Method 3

From a prepared description

Good for pipelines. The secret value must be protected in transit and in storage.

Method 4

By an operator or controller

Best for tokens that expire, since the operator refreshes them automatically.

!
Do not paste real passwords into shared places

Shell history, chat messages, tickets, and documents are common places where secrets leak. Prefer reading the password from a protected source, and use tokens with limited power rather than personal passwords.

Use a robot account, not a person

Registries usually let you create robot accounts, sometimes called service accounts or deploy tokens, meant for machines. Choose one with read-only permission for just the repositories the cluster needs. If a personal account is used, the pulls will fail the day that person leaves the company or changes their password.

5Attaching the Secret: Pod Level or Service Account Level

A secret does nothing until pods are told to use it. There are two main ways, and choosing well saves a lot of repetition.

Way 1: name it in the pod

Every pod description has an optional field called imagePullSecrets. It is a list of names of Secrets in the same namespace. When the pod is scheduled, the kubelet uses those secrets to pull the images for that pod. In a Deployment, the field sits inside the pod template, so that every pod the Deployment creates carries it.

This approach is explicit and clear. Anyone reading the description sees which secret is needed. But it must be repeated in every workload that pulls private images, which is tedious and easy to forget.

Way 2: attach it to the service account

A service account can also carry a list of image pull secrets. When a pod is created using that service account, Kubernetes automatically copies the list into the pod. So you attach the secret once to the account, and every pod that uses the account gets it. Most teams prefer this for a whole namespace, by attaching the secret to the default service account, or to a dedicated account used by their applications.

flowchart TD
    S["Image pull secret in namespace"] --> SA["Service account lists the secret"]
    S --> P1["Pod names the secret directly"]
    SA --> P2["Pod uses the service account"]
    P1 --> K["Kubelet gets the secret list"]
    P2 -->|"secrets copied into pod automatically"| K
    K --> PULL["Image pulled from private registry"]
        
FIG 2 — Two routes bring the same secret to the kubelet
Simple Analogy

Think of a company giving building passes. You can hand a pass to each worker every morning, which is naming the secret in every pod. Or you can attach the pass to the worker’s staff badge once, and it works every day, which is attaching the secret to the service account.

ApproachStrengthWeakness
Name it in each podExplicit, visible, preciseRepetitive, easy to forget on a new workload
Attach to the service accountSet once for many pods, fewer mistakesLess visible when reading a single workload, and applies to every pod using that account

The same-namespace rule

The secret must be in the same namespace as the pod. If a team has ten namespaces, each one needs its own copy of the secret. This is the most common reason a secret seems correct but is not used. It also means you need a plan for copying and refreshing the secret across namespaces, which we discuss later.

Multiple secrets

A pod may list more than one pull secret. This is useful when its containers come from different registries, for example one from your own registry and one from a partner’s. The kubelet chooses the credentials that match the registry of each image, and will try the available ones until one works.

i
Make new namespaces work automatically

Many teams create a small piece of automation so that every new namespace gets the pull secret and the service account link at once. This avoids a wave of ImagePullBackOff errors the first time a team deploys.

!
Changing the service account does not fix running pods

The list is copied into a pod when the pod is created. If you add a secret to a service account later, pods that already exist do not receive it. Recreate or restart them.

6Other Ways to Authenticate

A pull secret is the most common tool, but it is not the only one. Sometimes a different approach is simpler or safer.

Credentials configured on the node

The container runtime on each node can be given registry credentials directly, in a configuration file on the machine. Every pod on that node can then pull from that registry without any secret in the cluster. It is simple, but it has drawbacks. Every pod on the node shares the same access, the credentials must be placed on every node, and rotating them means touching every machine. It is used mostly in small or special setups.

Cloud credential providers

Managed Kubernetes services from big cloud providers often have their own private registries. They can give the kubelet short-lived credentials automatically, based on the identity of the machine or the workload. Kubernetes supports this through a plugin system for the kubelet, called credential providers. The kubelet asks the plugin for a fresh login whenever it needs to pull an image from a matching registry. No long-lived password is stored in the cluster at all.

Simple Analogy

A hotel may give guests a plastic key card at check-in that expires after they leave, rather than a metal key that could be copied and kept. Cloud credential providers are like those temporary cards: they work for a short time and refresh automatically.

Registry mirrors and pull-through caches

Some organisations run a registry near their cluster that fetches and keeps copies of images from elsewhere. Pods pull from this nearby registry. This can reduce delay, avoid limits set by public registries, and centralise credentials, because only the mirror needs a login to the upstream registry. The mirror itself may still need a pull secret for pods, or may be open only inside the private network.

ApproachWhere credentials liveGood whenWatch out for
Image pull secretSecret in each namespaceAny registry, any clusterCopying, rotating, and protecting secrets
Node configurationFiles on each nodeSmall clusters, uniform accessShared by all pods, hard to rotate
Cloud credential providerFetched on demand by the kubeletCloud registries with machine identityOnly works for supported registries
Mirror or pull-through cacheAt the mirrorLimits, speed, and central controlAnother system to run and secure

Public registry limits

Some public registries limit how many images an anonymous visitor may pull in a period of time. In a busy cluster, many nodes share a few outside addresses, and the limit is reached quickly. A pull secret with a proper account, or a mirror, often raises the limit. So a pull secret is sometimes used even for public images, not for privacy, but to avoid being throttled.

Real-World Use Case

A team runs a cluster in a managed cloud service with its images stored in the provider’s own registry. They rely on the cloud credential provider, so their pods pull with short-lived logins and they store no password anywhere. For a few third-party images from a partner’s registry, they add a small pull secret with a read-only token. For public base images, they use a pull-through mirror, so upstream limits never affect them.

i
Prefer identity over stored passwords

Whenever a registry can recognise your nodes or workloads directly, use that. Short-lived logins that refresh on their own are safer than long-lived passwords that must be copied and remembered.

7Architecture: The Pieces Involved

Several parts of the cluster, and some outside it, take part in every image pull. Knowing each one tells you where to look when something goes wrong.

The parts, from top to bottom

Part 1

The API server and the store

The API server is the front door of the cluster. It keeps Secrets, service accounts, and pod descriptions in the cluster’s store.

Part 2

The scheduler

Chooses which node a new pod should run on. It does not check credentials, so a pod may be placed on a node that cannot pull its image.

Part 3

The kubelet

Reads the pod’s secret list, fetches the Secret objects from the API server, and asks the runtime to pull.

Part 4

The container runtime

Software such as containerd or CRI-O that downloads image layers and starts containers.

Part 5

Credential providers

Optional plugins that the kubelet calls to obtain short-lived logins for certain registries.

Part 6

The registry

The outside server that checks the login and serves the image, often behind a network gateway.

Simple Analogy

Consider a company that sends drivers to a warehouse. The head office keeps the list of orders and passes, which is the API server. The dispatcher picks which driver goes, which is the scheduler. The driver carries the pass, which is the kubelet. The truck does the hauling, which is the runtime. The warehouse checks the pass, which is the registry. If any link breaks, the crate does not arrive.

Where the secret travels

The Secret is stored in the cluster’s store, usually in its base64 form, and sometimes encrypted at rest if the administrator has enabled that. When the kubelet needs it, it asks the API server for it. The kubelet is only allowed to read secrets for pods that are scheduled on its own node. This is a safety measure, so that one compromised node cannot read every secret in the cluster.

The kubelet then hands the login to the container runtime for the pull. It does not put it into the pod, and it does not write it to the pod’s environment.

The network between node and registry

The pull is a network trip from the node to the registry. Firewalls, proxies, and network policies can block it, even when the secret is perfect. Some organisations force all traffic through a proxy. Others use private links to their cloud registry. The nodes, not the pods, need to be able to reach the registry.

LayerQuestion it answersTypical problem
Pod descriptionDid we ask for the right image and secret?Wrong name, missing secret list
Secret objectIs it the right type, namespace, and registry address?Wrong type or wrong namespace
CredentialsAre they valid and allowed to read that image?Expired token or missing permission
NetworkCan the node reach the registry?Firewall or proxy rule
RegistryDoes the image and tag exist?Typo in tag, image deleted
Real-World Use Case

A team sees pods failing to pull on only one node group. The secret and image are correct, and other nodes pull fine. They discover that the new node group was created in a subnet with no route to the registry’s private address. Once the route is added, pulls succeed. The lesson was that pull failures are not always about secrets.

8Internal Working: One Pull, Step by Step

Let us follow a single image pull from the moment a pod is scheduled until the container starts.

The sequence

First, the pod is created and the scheduler assigns it to a node. The kubelet on that node notices the new pod and reads its description. For each container, it checks the image pull policy. If the image must be pulled, the kubelet gathers the credentials it may use: any secrets listed in the pod, and, if configured, credentials from node files or credential providers.

The kubelet then asks the container runtime to pull the image, passing the login. The runtime contacts the registry. The registry checks the login, and, if it is valid and allowed to read that image, it sends the image’s manifest, which is a small list of the pieces that make up the image, followed by the pieces themselves, called layers. When all layers arrive, the runtime unpacks them, and the kubelet starts the container.

sequenceDiagram
    participant K as Kubelet
    participant A as API server
    participant R as Container runtime
    participant G as Registry
    K->>K: New pod on this node, check pull policy
    K->>A: Fetch listed pull secrets
    A-->>K: Secret contents
    K->>R: Pull image with credentials
    R->>G: Request image with login
    G-->>R: Login accepted, send manifest
    R->>G: Request each layer
    G-->>R: Layers
    R-->>K: Image ready
    K->>R: Start container
        
FIG 3 — The kubelet fetches the secret, and the runtime uses it to talk to the registry

Follow the figure from top to bottom. The kubelet first learns which secrets to use, and asks the API server for them. It passes the login to the runtime. The runtime and the registry then exchange the login, the list of layers, and the layers themselves. Only when the image is ready does the container start.

Simple Analogy

This is like a courier collecting a large delivery in several boxes. The courier shows the pass, the warehouse gives a packing list, and then the boxes are carried out one by one. Only when all boxes are loaded does the delivery begin.

How the kubelet chooses a credential

When several credentials are available, the kubelet matches the registry address of the image against the registry addresses stored in the secrets. Matching may include the path, so a secret written for one part of a registry can be chosen over a more general one. If more than one matches, the kubelet may try them in order, and will stop at the first one that works. A failed attempt with one credential does not stop the others from being tried.

What happens after a failure

If the pull fails, the kubelet reports an error such as ErrImagePull. It then waits before trying again, and the waiting time grows each round, up to a limit of a few minutes. While it waits, the pod status shows ImagePullBackOff. This is called back-off, and it prevents a broken pull from hammering the registry. Once the cause is fixed, the next attempt succeeds, though you may wait a little for the timer.

ErrImagePull
the pull just failed
ImagePullBackOff
waiting before trying again
Minutes
the wait grows up to a maximum of a few minutes
i
A restart of the pod skips the wait

After fixing a secret, deleting the stuck pod makes its controller create a new one, which tries at once. This is often quicker than waiting for the timer.

Images already on the node

If an image is already on the node, the policy may allow a pod to use it without a new pull. This means a pod without any secret could start using an image that another pod pulled earlier with proper credentials. This is a known subtlety. For sensitive images, consider using the always-pull policy, so that the registry is asked every time, or use newer Kubernetes features that check credentials even for cached images, where they are available in your version.

!
Cached images can hide a missing secret

A workload may run fine on one node because the image is cached, and fail on a new node where it must be pulled. If a pod works “sometimes,” suspect this. Test with a fresh node or with the always-pull policy.

9When Pulls Fail: A Guide to ImagePullBackOff

Almost every team has faced this error. The good news is that the causes are few, and a fixed routine finds them quickly.

Start with the message

Describe the stuck pod and read its events. The events tell you the real reason. Messages mention things like authentication required, access denied, image not found, connection timed out, or unauthorised. Each points to a different layer of the problem, so reading the exact words saves much time.

flowchart TD
    S["Pod shows ImagePullBackOff"] --> E["Read the pod events for the exact message"]
    E --> Q1{"Message says not found?"}
    Q1 -->|"Yes"| F1["Check image name, tag, and registry spelling"]
    Q1 -->|"No"| Q2{"Message says unauthorised or denied?"}
    Q2 -->|"Yes"| F2["Check secret exists, is in the same namespace, and is referenced"]
    F2 --> F3["Check credentials are valid and have read permission"]
    Q2 -->|"No"| Q3{"Message says timeout or no route?"}
    Q3 -->|"Yes"| F4["Check network, proxy, firewall, and DNS from the node"]
    Q3 -->|"No"| F5["Check rate limits and registry status"]
        
FIG 4 — A simple path from the error message to the likely cause

The figure shows a routine you can repeat. First read the message. If the image is not found, the problem is the name or tag. If access is denied, the problem is the secret or the credentials. If the connection times out, the problem is the network. If none of these fit, look at limits and the health of the registry.

Simple Analogy

If a parcel does not arrive, the tracking page will say one of three things: wrong address, nobody would sign for it, or the road was closed. Each needs a different fix. Reading the message first tells you which of the three you face.

The usual causes, in order of how often they occur

CauseHow it looksFix
Secret is in a different namespaceAccess denied, though the secret existsCreate it in the pod’s namespace
Pod does not reference the secretAnonymous access refusedAdd the secret to the pod or to its service account
Wrong Secret typeSecret ignoredRecreate as a docker-registry Secret
Registry address does not matchSecret exists but is not chosenUse the same server name as in the image
Expired or revoked tokenWorked before, fails nowRefresh the token and update the Secret
Account lacks read permissionDenied for some repositories onlyGrant read access to that repository
Wrong image name or tagNot foundCorrect the spelling or push the missing tag
Network or proxy blockTimeout or no routeFix routing, proxy, or firewall for the node
Rate limit reachedToo many requestsAuthenticate, use a mirror, or spread pulls
Wrong CPU typeNo matching platformPush an image built for the node’s architecture

A useful check: look from the node

If you can reach the node, try pulling the image by hand from there using the runtime’s tools and the same login. If it works by hand, the problem is with how Kubernetes passes the secret. If it fails by hand, the problem is with the credentials, network, or registry. This splits the search in half.

i
Check what the secret really contains

Decode the secret’s value and read the registry address and username. A missing letter, an extra space, or the wrong server name is a very common cause, and it is easy to see once you look.

!
Be careful when decoding in shared spaces

Decoding a secret reveals the password on your screen and in your terminal history. Do it only in a private session, and never paste the output into a chat or ticket.

10Data Flow and Lifecycle of a Pull Credential

A pull credential has a life of its own: it is issued, stored, distributed, used, rotated, and finally revoked. Managing the whole life matters more than the first setup.

1

Issue

A robot account or token is created in the registry with read-only access to chosen repositories, and a clear name and owner.

2

Store

The credential is placed in a secure secret store or a protected pipeline variable, not in plain text in a repository.

3

Create the Secret

The credential becomes a Kubernetes Secret of the correct type in each namespace that needs it.

4

Attach

The Secret is linked to pods or to service accounts so that workloads use it.

5

Use

Kubelets fetch the Secret when they pull images. The registry records each pull under the robot account’s name.

6

Rotate

On a schedule, or when a token expires, a new credential replaces the old one everywhere it is stored.

7

Revoke

If a credential leaks or is no longer needed, it is deleted at the registry, and all copies are removed from the cluster.

Simple Analogy

This is the life of a building pass. It is issued to a named person, stored safely by the office, copied to the right doors, used every day, replaced when it wears out, and cancelled if lost. A pass that is never renewed or cancelled becomes a hidden risk.

Expiry is the silent troublemaker

Some registries, especially those run by cloud providers, hand out login tokens that expire after hours or days. A pull secret built from such a token works perfectly at first and then, quietly, stops working. The cluster looks fine until a new pod needs a pull, perhaps at night when a node is replaced, and then it fails. Long-lived static tokens avoid this but are riskier. The best answer is automatic refresh, described in the next chapter.

Credential typeLifetimeRisk if leakedEffort to maintain
Personal passwordLong, until changedHigh, and tied to a personLow at first, painful later
Robot account with static tokenLong, until rotatedMedium, if read-only and narrowMedium, needs a rotation plan
Short-lived tokenHoursLow, expires soonHigh unless automated
Identity-based loginMinutes, refreshed by the kubeletVery lowLow once set up
!
Nobody notices until a node is replaced

Existing pods keep running with images already on the node. The failure appears only when a new node starts or an image must be pulled again. Test rotation in advance rather than discovering an expired token during an incident.

11Automating and Rotating Pull Secrets

Copying a secret by hand into thirty namespaces, and renewing it every twelve hours, is not a plan. Automation turns pull secrets from a chore into a background service.

Three jobs to automate

Job 1

Distribute

Create the Secret in every namespace that needs it, including new ones as they appear.

Job 2

Refresh

Get a fresh token before the old one expires, and update every copy of the Secret.

Job 3

Attach

Link the Secret to service accounts so that new workloads use it without extra steps.

Common approaches

One approach is an external secrets operator. It reads credentials from a central store, such as a cloud secret manager or a vault, and creates and updates Kubernetes Secrets from them on a schedule. Change the value in the central store, and every copy is updated. Another approach is a small controller or scheduled job that logs in to the registry, gets a fresh token, and writes it into the Secrets. A third is to use a tool that replicates one Secret across selected namespaces.

Teams that use GitOps, where the cluster follows files kept in a repository, must be careful. The Secret must never be stored in plain form in the repository. Sealed or encrypted secrets, or references to an external store, keep the repository safe.

flowchart LR
    ST["Central secret store or registry token service"] --> OP["Operator or scheduled job"]
    OP --> N1["Secret in namespace A"]
    OP --> N2["Secret in namespace B"]
    OP --> N3["Secret in namespace C"]
    N1 --> SA1["Service account A links the Secret"]
    N2 --> SA2["Service account B links the Secret"]
    N3 --> SA3["Service account C links the Secret"]
        
FIG 5 — One source of truth feeds every namespace, and service accounts link the secret to pods

In the figure, a single trusted source holds the real credential. An operator or job copies it into every namespace and refreshes it when needed. Each namespace’s service account links the Secret, so new workloads get it automatically. Changing the credential means changing only the source.

Simple Analogy

A head office keeps the master list of passes, and a courier delivers fresh passes to every branch each morning. Branch managers never need to think about it. If a pass is lost, head office cancels it once, and all branches receive a new one.

Rotation without downtime

To rotate safely, create the new credential first, and update the Secrets while the old credential still works. Watch that pulls succeed with the new one. Only then revoke the old credential. Because pods only need the Secret at the moment of a pull, there is no need to restart running pods, unless they were created with a stale copy of a service account’s list.

i
Make rotation boring

Rotate on a fixed calendar even when nothing has gone wrong. A process practised often is a process that works on the day you need it in a hurry.

Real-World Use Case

A company’s private registry hands out tokens that last twelve hours. They install an operator that refreshes the pull Secret every six hours in all thirty namespaces, and a rule that makes new namespaces receive it at creation. Node replacements at night no longer fail, and the platform team no longer receives after-hours calls about ImagePullBackOff.

12Security of Pull Secrets

A pull secret is a key to your company’s software. Handle it with the care you would give any key to a valuable warehouse.

What could go wrong

If an attacker obtains a pull credential, they may download your private images, study them for weaknesses, and find any secrets accidentally baked inside. If the credential has write permission, they could even push a poisoned image that your cluster would then run. The strength of your defences should match how powerful the credential is.

Simple Analogy

Think of a spare key hidden under a doormat. If the key opens only a storage cupboard, a thief gains a little. If it opens the main vault, a thief gains everything. So give out keys that open as little as possible.

Controls to put in place

Control 1

Read-only, narrow credentials

Give the robot account permission to pull only the repositories it needs. Never give it permission to push or to manage the registry.

Control 2

Limit who can read Secrets

Use role-based access control, or RBAC, so that only those who truly need it can read Secrets in a namespace. Listing Secrets is as powerful as reading them.

Control 3

Encrypt Secrets at rest

Turn on encryption for the cluster’s store, so that a stolen backup does not reveal the credentials.

Control 4

Keep them out of repositories

Never commit plain Secrets to version control. Use encrypted forms or external secret stores.

Control 5

Prefer short-lived and identity-based logins

They lose value quickly if leaked, and need no long-term storage.

Control 6

Watch registry logs

Pulls by an unknown address, at odd hours, or of unusual images are signs of theft.

Who can use a secret?

Anyone who can create a pod in a namespace can reference any pull secret in that namespace, and thereby use its power to pull images. So a pull secret in a shared namespace gives its access to everyone who can create pods there. If teams should not share access, give them separate namespaces and separate credentials.

Scope credentials by team

A single company-wide credential is convenient but dangerous. If it leaks, every image is exposed. Instead, use one credential per team or per environment, limited to the repositories that team uses. A leak then affects little, and the source is easier to trace.

RiskWhat could happenProtection
Broad credential with write accessAttackers push a poisoned imageRead-only, per-repository access
Secrets readable by manyAnyone in the namespace can steal the credentialTight RBAC, avoid list and read rights
Plain Secret in a repositoryCredential leaks through copies of the codeEncrypted or external secrets
Unencrypted store or backupsStolen backup reveals credentialsEncryption at rest, protected backups
Never rotatedAn old leak stays useful foreverRegular rotation and expiry
Cached images bypass credentialsPods run private images without permissionAlways-pull policy for sensitive images, or newer credential checks
!
Base64 is not a lock

Anyone who can read a Secret can turn it back into the password in seconds. Base64 only changes how the text looks. Real protection comes from access rules and encryption, not from encoding.

Real-World Use Case

A security review finds that the company used one registry administrator account for all pull secrets in all clusters, and copies were stored in a shared repository. The team creates read-only robot accounts for each team, moves the values into a secret manager, adds an operator to distribute them, and revokes the administrator token. The exposure from any single leak falls from the whole registry to a small set of repositories.

13Advantages, Disadvantages, and Trade-offs

Pull secrets are the standard, simple answer for private registries. They also have costs that grow with the size of your cluster.

Advantages

  • Works with any registry that uses standard logins.
  • Built into Kubernetes, with no extra software required.
  • Keeps credentials out of images and application code.
  • Easy to attach to many pods through a service account.
  • Supports several registries at once for a single pod.
  • Simple to understand and to test by hand.

Disadvantages

  • Must be copied into every namespace that needs it.
  • Long-lived static credentials are risky if leaked.
  • Short-lived tokens need automation to refresh.
  • Stored as base64, so protection depends on access rules and encryption.
  • Anyone who can create pods in the namespace can use the secret.
  • Cached images can bypass credential checks on a node.

The trade-offs in plain words

ChoiceBenefitCost
One shared credentialVery simple to set upA leak exposes everything
Credential per teamSmall blast radius, easy to traceMore to create and rotate
Static tokenNever expires unexpectedlyValuable to a thief for a long time
Short-lived tokenLittle value if stolenNeeds automatic refresh
Always-pull policyRegistry checks every startMore traffic and slower starts
Pull-through mirrorSpeed, limits avoided, central controlOne more system to run and secure
Simple Analogy

A single master key is easy to carry but disastrous to lose. A ring of small keys, one for each door, is fussier to manage but each lost key opens only one door. Choosing between them is choosing between convenience and safety.

How it compares with the alternatives

ApproachStrengthWeakness
Image pull secretsUniversal and simpleCopying and rotation effort
Cloud credential providersNo stored password, automatic refreshLimited to supported registries
Node-level credentialsNo per-namespace secretsShared by every pod on the node
Public images onlyNo credentials at allNot possible for private code
i
A good default

Use identity-based credentials where your cloud supports them. Use narrow, read-only pull secrets for everything else, distributed and refreshed by automation.

14Design Patterns and Anti-patterns

Patterns are ways of arranging things that many teams have found to work. Anti-patterns are shortcuts that cause trouble later.

Helpful patterns

Pattern 1

Service account carries the secret

Attach the pull secret to the service account used by workloads, so that new deployments work without extra steps.

Pattern 2

One source of truth

Keep the credential in a central store, and let an operator copy it into namespaces.

Pattern 3

Namespace bootstrap

Create the Secret and link it to the service account as part of creating any new namespace.

Pattern 4

Robot account per team

Give each team its own read-only account limited to its repositories.

Pattern 5

Use digests for important images

Refer to images by their unchangeable fingerprint, so that a changed tag cannot swap in a different image.

Pattern 6

Local mirror for public images

Pull public images through your own registry, avoiding limits and keeping control of what enters the cluster.

Simple Analogy

A well-run hotel does not ask each guest to fetch a key from the manager. Each new booking automatically gets a key card made and linked to the room. New namespaces getting their pull secret automatically follows the same idea.

Anti-patterns to avoid

ANTI-PATTERN-01 Avoid
Problem

Using a personal login or a registry administrator account for the cluster’s pull secret.

Why It’s Harmful

Pulls fail when the person leaves or changes their password, and a leak exposes far more than images: it may allow pushing and deleting.

Correct Approach

Create dedicated read-only robot accounts limited to the needed repositories.

ANTI-PATTERN-02 Avoid
Problem

Committing the plain Secret description, with its base64 password, into a code repository.

Why It’s Harmful

Anyone with repository access can decode it, and old versions live forever in history. Many leaks start this way.

Correct Approach

Use sealed or encrypted secrets, or references to an external secret store, and rotate any credential that was ever committed.

ANTI-PATTERN-03 Avoid
Problem

Building a pull secret from a short-lived token and never refreshing it.

Why It’s Harmful

It works until the token expires, and then new pods and new nodes fail to start, often at the worst time.

Correct Approach

Automate refresh, or use identity-based credentials that the kubelet renews itself.

ANTI-PATTERN-04 Avoid
Problem

Baking registry passwords into images or into application configuration to make pulls work.

Why It’s Harmful

Images are copied and shared, so the password travels with them. It also does not work, because the image must be pulled before it can be read.

Correct Approach

Keep credentials in Secrets and let the kubelet use them outside the image.

ANTI-PATTERN-05 Avoid
Problem

Relying on the latest tag with a pull policy that never checks the registry.

Why It’s Harmful

Different nodes run different versions of the same tag, and pulls may succeed by luck on cached nodes while failing on new ones.

Correct Approach

Use fixed version tags or digests, and choose the pull policy on purpose.

15Best Practices and Common Mistakes

A short list of habits that keep image pulls reliable and safe, and the mistakes that most often cause outages.

Best practices

1

Use dedicated read-only accounts

Create a robot account per team or environment, limited to the repositories it needs.

2

Prefer identity-based logins

Where your cloud registry supports it, let the kubelet fetch short-lived credentials on its own.

3

Attach secrets to service accounts

Link the Secret once per service account, and use that account for workloads in the namespace.

4

Automate distribution and rotation

Use an operator or job to copy and refresh Secrets, and include new namespaces automatically.

5

Protect the Secrets

Limit read and list access, encrypt at rest, and keep plain values out of repositories.

6

Pin image versions

Use fixed tags or digests instead of moving tags, so behaviour is predictable across nodes.

7

Monitor pull failures

Alert on pods stuck in ImagePullBackOff and on rising registry errors, before customers notice.

8

Practise rotation and recovery

Rehearse replacing a credential and adding a new node, so nobody is surprised during an incident.

Simple Analogy

Handling pull secrets well is like managing keys in an office. Keep a register of who holds which key, replace keys on a schedule, collect them when people leave, and never make more copies than needed.

Common mistakes

MistakeWhat goes wrongBetter habit
Creating the Secret in the wrong namespacePods cannot see itCreate it in the pod’s namespace, and automate for new ones
Creating a generic Secret instead of a registry SecretKubernetes ignores it for pullingUse the docker-registry type
Forgetting the Secret on init containers’ imagesThe pod stays stuck before startingRemember that all images in a pod use the same list
Adding a Secret to a service account and expecting old pods to changeOld pods still lack itRestart or recreate the pods
Using a different registry address in the SecretThe Secret is never matchedCopy the server name from the image
Relying on one node’s cached imageWorks on that node, fails elsewhereTest on a fresh node, and consider always-pull for sensitive images
Ignoring rate limitsPulls fail during busy rolloutsAuthenticate, or use a mirror
!
Do not paste secrets into tickets while debugging

During an outage, people copy commands and outputs into chats. A decoded Secret pasted into a shared channel becomes a leak. Share only the registry name and username, never the password.

A gentle start plan

In week one, create a read-only robot account for one team, make a registry Secret in one namespace, attach it to the default service account, and deploy one application to prove it works. In week two, write the automation so that every new namespace gets the Secret. In week three, add refresh and rotation, and encrypt Secrets at rest. In week four, review permissions and set up alerts for pull failures. Then repeat for other teams.

16Monitoring, Logging, and Troubleshooting

You do not want to learn about an expired credential from an angry customer. Watch for the signs early, and keep a simple routine for fixing problems.

What to watch

Stuck pods
count of pods in ErrImagePull or ImagePullBackOff
Pull errors
failed image pulls reported by kubelets
Token age
time left before each credential expires
Coverage
namespaces that have the Secret and the link
Simple Analogy

A careful driver watches the fuel gauge and does not wait for the engine to stop. A token-age gauge and a stuck-pod counter are your fuel gauge and warning light.

Where the signals appear

Signal 1

Pod events

Show the exact reason a pull failed, in words from the registry or the runtime.

Signal 2

Kubelet logs

Record each attempt, including which credential source was used.

Signal 3

Cluster metrics

State metrics can count pods waiting with an image pull reason, ready for alerts.

Signal 4

Registry logs

Show who pulled what and when, and which logins failed.

Alerts worth having

Alert when any pod has been stuck pulling an image for more than a few minutes. Alert when a credential will expire within a few days, or a refresh job fails. Alert when a new namespace lacks the pull Secret. Also alert on unusual registry activity, such as pulls from unknown addresses, which might mean a stolen credential.

Troubleshooting the usual suspects

SymptomLikely causeWhere to look
New namespace: every pod stuck pullingThe Secret was never created thereSecrets in the namespace and the service account’s list
Worked yesterday, fails todayToken expired or was revokedExpiry time and refresh job logs
Works on some nodes onlyCached image on one node, or network differenceImage cache and network routes of failing nodes
Denied for one repository onlyAccount lacks permission for itThe robot account’s repository rules
Secret exists but ignoredWrong type or wrong registry addressType field and decoded server name
Too many requests errorRegistry rate limitAuthentication status and mirror configuration
Pulls slow during big rolloutsAll nodes pulling at onceMirror capacity and staggered rollouts
i
Change one thing at a time

When several fixes seem possible, try one, wait for the next attempt, and look again. Changing many things at once makes it impossible to know what worked.

Emergency path

If a credential leaks, revoke it at the registry first, since that stops the harm at once. Then create a new credential, update the Secrets, and restart any pods that are stuck. Afterwards, check the registry logs to see what the old credential was used for, and record the lessons.

17Real-World Examples

Three short stories show the ideas in action. The details are typical rather than taken from any one company.

Example 1: The missing namespace secret

Real-World Use Case

A new team gets its own namespace and deploys its first application. Every pod sticks in ImagePullBackOff. The events say access is denied. The team checks the image name, which is right, and the registry, which is fine. Finally they notice that the pull Secret exists only in the older namespaces. The platform team adds automation so that any new namespace receives the Secret and the service account link at creation. The problem never returns.

Example 2: The token that expired at night

Real-World Use Case

At three in the morning, a node in a cloud cluster is replaced during routine maintenance. Its pods move to a new node and cannot pull their images. The pull Secret was made from a token that lasts twelve hours, and was last created two days ago. Existing nodes still had cached images, so nobody noticed until the new node needed to pull. The team installs a refresh operator and adds an alert for tokens expiring soon.

Example 3: The leaked administrator token

Real-World Use Case

A developer accidentally commits a plain Secret file to a public repository. It contains a registry administrator token. A scanning tool notices within minutes and warns the security team. They revoke the token at the registry, review the registry logs for unusual pulls and pushes, and find none. They then replace the administrator token with read-only, per-team accounts and move the values into an encrypted store. What could have been a disaster becomes a short, well-handled incident.

Simple Analogy

These stories are like three kinds of lost-key events at an office: a new branch that never received its key, a key card that quietly expired, and a master key dropped in the street. The fixes are the same in spirit: give keys automatically, renew them on time, and never hand out a master key when a small one will do.

What the stories share

In each case, the fix was less about clever tricks and more about a steady process: automate the boring parts, limit what each credential can do, and watch for early signs. Teams that built that process spent far less time fighting fires.

Give every workload a key that opens only what it needs, and make sure that key renews itself.

18Frequently Asked Questions

Short answers to questions that beginners often ask.

Q1What is an image pull secret?

It is a Kubernetes Secret of the registry-login type. It holds the address of a registry and the credentials needed to pull images from it, and the kubelet uses it when downloading images for pods.

Q2Why do I get ImagePullBackOff?

The pull failed and Kubernetes is waiting before it tries again. Common causes are a wrong image name or tag, missing or wrong credentials, a secret in the wrong namespace, network blocks, or rate limits. Read the pod events for the exact reason.

Q3Can a pod use a secret from another namespace?

No. The pull secret must be in the same namespace as the pod. You need a copy in each namespace, ideally created and refreshed automatically.

Q4Should I attach the secret to each pod or to the service account?

For most teams, the service account is easier, since one link covers all pods that use the account. Naming the secret in the pod is more explicit. Either works, and they can be combined.

Q5Do I need a pull secret for public images?

Not for access. But anonymous pulls from some public registries are limited, so using a login or a mirror can prevent failures in busy clusters.

Q6Is a Secret encrypted?

Not by default. It is stored in base64, which is only an encoding. Turn on encryption at rest for the cluster store, and limit who can read Secrets.

Q7What about registries from cloud providers?

Many cloud registries work with credential providers that give the kubelet short-lived logins automatically. That avoids storing passwords in the cluster. Check the documentation of your provider for the supported setup.

Q8How often should I rotate credentials?

As often as your process can handle safely. For static tokens, a regular calendar such as every few months is common, plus immediately after any suspected leak. For short-lived tokens, refresh well before they expire.

Q9Why does my pod work on one node and fail on another?

One node may already have the image cached, so it does not need to pull, while the other must pull and lacks working credentials or a network path. Test with the always-pull policy or on a fresh node.

Q10Do running pods need a restart after I change the secret?

Running pods do not need the secret again unless they are recreated. The secret is used only when a pull happens. But if you added a secret to a service account, existing pods will not get it, so recreate them if they need to pull.

Q11Can I use several secrets in one pod?

Yes. List all of them. The kubelet picks the credentials that match each image’s registry.

Q12Where should I start?

Create a read-only robot account, make a registry Secret in one namespace, attach it to a service account, and deploy one application. Then automate creation for new namespaces and set up refresh and alerts.

19Summary and Key Takeaways

A last look at the whole picture, in plain words.

Private container images sit behind a login, like books in a members-only library. Kubernetes needs a membership card to borrow them, and that card is the image pull secret. It is a Secret of a special type that holds a registry address and credentials. The kubelet on each node reads it and uses it, together with the container runtime, to pull images before a pod starts.

The secret must live in the same namespace as the pod, and must be attached either directly in the pod or, more conveniently, through the service account. Other options exist, such as node-level credentials, cloud credential providers, and mirrors. Identity-based, short-lived logins are safest, because nothing long-lived needs storing.

When pulls fail, read the pod events, and follow the simple path from message to cause. Over the long term, treat credentials as things with a life: issue narrow read-only accounts, distribute and refresh them automatically, protect them with access rules and encryption, and revoke them quickly when needed. Do this, and image pulls become a quiet part of the background.

Key Takeaways

  • A pull secret is a membership card for a private registry — a Secret of the registry-login type that the kubelet uses to download images before pods start.
  • Namespace and reference decide whether it works — the Secret must be in the pod’s namespace, and named by the pod or by its service account.
  • The registry address inside must match the image — a wrong type, wrong key, or wrong server name makes Kubernetes ignore the Secret.
  • Prefer identity over stored passwords — cloud credential providers and short-lived tokens leave little to steal, while static tokens need careful rotation.
  • Read the events to fix ImagePullBackOff — not found, denied, and timeout point to the name, the credentials, and the network respectively.
  • Automate distribution and refresh — one source of truth feeding every namespace prevents expired tokens and missing secrets, especially on new nodes and namespaces.
  • Base64 is not protection — use read-only per-team accounts, tight RBAC, encryption at rest, and keep plain Secrets out of repositories.