Not able to access kubernetes api from inside a pod container

前端 未结 2 1042
臣服心动
臣服心动 2021-01-21 21:43

I have created a hashicorp vault deployment and configured kubernetes auth. The vault container calls kubernetes api internally from the pod to do k8s authentication, and that c

相关标签:
2条回答
  • 2021-01-21 22:08

    Finally I have figured out what went wrong:

    my payload.json content was wrong

    it should be like this:

    {
          "kubernetes_host": "https://kubernetes",
          "kubernetes_ca_cert": <kubectl exec to vault pod and cat  /var/run/secrets/kubernetes.io/serviceaccount/ca.crt, now make the cert one line by following this answer: https://stackoverflow.com/a/14580203/2054147>
    }
    

    Now below endpoint is working fine and returning the desire client_token

    curl --request POST --data @payload2.json http://127.0.0.1:8200/v1/auth/kubernetes/login
    

    Thanks @John for helping me to figure out the initial issue with kubernetes_host.

    0 讨论(0)
  • 2021-01-21 22:09

    Your login request is being sent to the tokenreview endpoint on port 80. I think this is because your kubernetes_host specifies a http URL. The 500 response is because it's not listening on port 80, but on 443 instead (as you can see in your service list output).

    Try changing to https when configuring the auth, i.e.

    payload.json
    
    {
        "kubernetes_host": "https://kubernetes",
        "kubernetes_ca_cert": <k8s service account token>
    }
    
    0 讨论(0)
提交回复
热议问题