Why Kubernetes is not attaching my secret into my pod?

9/28/2018

I already created my secret as recommend by Kubernetes and followed the tutorial, but the pod isnt with my secret attached.

As you can see, i created the secret and described it. After i created my pod.

$ kubectl get secret my-secret --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode
{"auths":{"my-private-repo.com":{"username":"<username>","password":"<password>","email":"<email>","auth":"<randomAuth>="}}}

$ kubectl create -f my-pod.yaml
pod "my-pod" created

$ kubectl describe pods trunfo
Name:         my-pod
Namespace:    default
Node:         gke-trunfo-default-pool-07eea2fb-3bh9/10.233.224.3
Start Time:   Fri, 28 Sep 2018 16:41:59 -0300
Labels:       <none>
Annotations:  kubernetes.io/limit-ranger=LimitRanger plugin set: cpu request for container container-trunfo
Status:       Pending
IP:           10.10.1.37
Containers:
  container-trunfo:
    Container ID:   
    Image:          <my-image>
    Image ID:       
    Port:           9898/TCP
    State:          Waiting
      Reason:       ErrImagePull
    Ready:          False
    Restart Count:  0
    Requests:
      cpu:        100m
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-hz4mf (ro)
Conditions:
  Type           Status
  Initialized    True 
  Ready          False 
  PodScheduled   True 
Volumes:
  default-token-hz4mf:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-hz4mf
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason                 Age   From                                            Message
  ----     ------                 ----  ----                                            -------
  Normal   Scheduled              4s    default-scheduler                               Successfully assigned trunfo to gke-trunfo-default-pool-07eea2fb-3bh9
  Normal   SuccessfulMountVolume  4s    kubelet, gke-trunfo-default-pool-07eea2fb-3bh9  MountVolume.SetUp succeeded for volume "default-token-hz4mf"
  Normal   Pulling                3s    kubelet, gke-trunfo-default-pool-07eea2fb-3bh9  pulling image "my-private-repo.com/my-image:latest"
  Warning  Failed                 3s    kubelet, gke-trunfo-default-pool-07eea2fb-3bh9  Failed to pull image "my-private-repo.com/my-image:latest": rpc error: code = Unknown desc = Error response from daemon: Get https://my-private-repo.com/v1/_ping: dial tcp: lookup my-private-repo.com on 169.254.169.254:53: no such host
  Warning  Failed                 3s    kubelet, gke-trunfo-default-pool-07eea2fb-3bh9  Error: ErrImagePull
  Normal   BackOff                3s    kubelet, gke-trunfo-default-pool-07eea2fb-3bh9  Back-off pulling image "my-private-repo.com/my-image:latest"
  Warning  Failed                 3s    kubelet, gke-trunfo-default-pool-07eea2fb-3bh9  Error: ImagePullBackOff

What can i do to fix it?

EDIT

This is my pod:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: my-private-repo/images/<my-image>
    ports:
    - containerPort: 9898
  imagePullSecrets:
  - name: my-secret

As we can see, the secret is defined as expected, but not attached correctly.

-- Brenno Leal
docker
kubernetes

1 Answer

9/28/2018

You did not get as far as secrets yet. Your logs say

Failed to pull image "my-private-repo.com/my-image:latest": rpc error: code = Unknown desc = Error response from daemon: Get https://my-private-repo.com/v1/_ping: dial tcp: lookup my-private-repo.com on 169.254.169.254:53: no such host Warning Failed 3s kubelet, gke-trunfo-default-pool-07eea2fb-3bh9 Error: ErrImagePull

Which means that your pod cannot event start because the image is not available. Fix that, and if you still have problem with secrets after you observer pod state "ready" post your yaml definition.

-- Andrew Savinykh
Source: StackOverflow