Home › Kubernetes

error: a container name must be specified for pod (Kubernetes) — how to fix

error: a container name must be specified for pod web-7d9f8c6b5-x2kqp, choose one of: [app istio-proxy] or one of the init containers: [istio-init]

Quick fix: Pass the container with -c: kubectl logs web-7d9f8c6b5-x2kqp -c app or kubectl exec -it web-7d9f8c6b5-x2kqp -c app -- sh. For all containers: kubectl logs <pod> --all-containers=true.

What it means

kubectl logs, kubectl exec and kubectl attach work on one container. When a pod has several and kubectl can't pick a default, it stops and lists the names: regular containers after choose one of: and init containers after or one of the init containers:.

List the container names yourself:

kubectl get pod web-7d9f8c6b5-x2kqp -o jsonpath='{.spec.containers[*].name}{"\n"}{.spec.initContainers[*].name}{"\n"}'

Fix 1: name the container with -c

kubectl logs web-7d9f8c6b5-x2kqp -c app
kubectl logs web-7d9f8c6b5-x2kqp -c app -f --tail=100
kubectl exec -it web-7d9f8c6b5-x2kqp -c app -- sh

Init container logs work the same way:

kubectl logs web-7d9f8c6b5-x2kqp -c istio-init

Logs of the previous (crashed) instance of a container:

kubectl logs web-7d9f8c6b5-x2kqp -c app --previous

Fix 2: logs from all containers at once

kubectl logs web-7d9f8c6b5-x2kqp --all-containers=true
kubectl logs web-7d9f8c6b5-x2kqp --all-containers=true --prefix

--prefix adds the pod and container name to each line.

By label across several pods:

kubectl logs -l app=web -c app --tail=50
kubectl logs -l app=web --all-containers=true

Or target a Deployment (kubectl picks one of its pods):

kubectl logs deploy/web -c app

Fix 3: set a default container

Recent kubectl versions read the kubectl.kubernetes.io/default-container annotation on the pod and use that container when -c is omitted, printing Defaulted container "app" out of: app, istio-proxy. Add it to the pod template:

spec:
  template:
    metadata:
      annotations:
        kubectl.kubernetes.io/default-container: app

If you still get the error after adding it, your kubectl is too old to use the annotation; upgrade kubectl or keep using -c.

Where the extra containers come from

You might not have added a second container yourself:

kubectl describe pod <pod> shows every container, its state and restart count, which also tells you which one is failing.

Last updated 2026-12-01.