Access to POD and SERVICE by API into a POD

A question theory says that Resources can be accessed within the same Cluster.

I understand then that if I start a Proxy:
$ kubectl proxy

I could access its resources by API from the console:

$ curl http://127.0.0.1:8001/api/v1/pods

$ curl http://127.0.0.1:8001/api/v1/services

$ curl http://127.0.0.1:8001/api/v1/secrets

But how could you access the same information, within a POD?

$ kubectl exec --stdin --tty dummy-01 – /bin/bash
root@dummy-01:/# curl http://127.0.0.1:8001/api/v1/pods

tt

How i can do that.

Thank you.

When you use “kubectl proxy” from your server it uses your current kubeconfig credentials to authenticate to the API server and proxies your API server URL to the provided “kubectl proxy” port (default 8001).

Without “kubectl proxy” you would usually -

  1. Do a curl to API server URL with required key/cert info (args - --cacert, --key, --cert) OR
  2. Use kubectl commands (which again uses cert info from your kubeconfig - default location ~/.kube/config)

Now, within a pod, you would need your kubeconfig file and kubectl installed to use kubectl proxy the same way.

Hope this answers your question.

I could enter, starting the proxy:
$kubectl proxy

The pattern to use is:
“IP:PUERTO (CLUSTER) + api + v1 + namespaces + NAMESPACE-NAME + TYPE-COMPONENTs”

With these i could get the información by API of the Kubernetes components:

$curl http://127.0.0.1:8001/api/v1/namespaces/default/pods
$curl http://127.0.0.1:8001/api/v1/namespaces/default/deployments
$curl http://127.0.0.1:8001/api/v1/namespaces/default/secrets

The problem is when i enter to the POD, there i can not:

What can i do ?

Thank you.

Hello, @maktup
You should try in your current terminal not inside of the Pod. You enabled the proxy to work with the localhost and port 8081.