Access Kubernetes api from within a pod container

0 votes

I'm trying to access kuberneets api from within a pod container but i get an error saying "unauthorized". This only happens in Kubernetes 0.18.0. Also it works perfectly fine when we use the machines external IP

Aug 29, 2018 in Kubernetes by lina
• 8,220 points
2,812 views

2 answers to this question.

0 votes

I think you're missing a security token was not required in the previous versions, hence you started getting the error only in this updated version of kubernetes.

I think a simpler solution than running a proxy or installing golang on your container. Have a look at the example.

KUBE_TOKEN=$(</var/run/secrets/kubernetes.io/serviceaccount/token)
curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/default/pods/$HOSTNAME

answered Aug 29, 2018 by Kalgi
• 52,350 points
0 votes

wget version:

KUBE_TOKEN=$(</var/run/secrets/kubernetes.io/serviceaccount/token)    
wget -vO- --ca-certificate /var/run/secrets/kubernetes.io/serviceaccount/ca.crt  --header "Authorization: Bearer $KUBE_TOKEN" https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/default/pods/$HOSTNAME
answered Aug 29, 2018 by Nilesh
• 7,060 points

Related Questions In Kubernetes

0 votes
2 answers

How can I access a service installed on Kubernetes from anywhere?

if u want to directly want to ...READ MORE

answered Jul 26, 2020 in Kubernetes by Akash Gupta
1,362 views
0 votes
1 answer

how can i access two containers that are inside a pod from the browser with IP address?

Just do port forward. kubectl port-forward [nginx-pod-name] 80:80 kubectl ...READ MORE

answered Jul 18, 2019 in Kubernetes by Sirajul
• 59,230 points
2,103 views
0 votes
1 answer

How to use gravitational teleport in a container/kubernetes environment?

You can use teleport to augment kubernetes ...READ MORE

answered Jun 28, 2018 in Kubernetes by ajs3033
• 7,300 points
2,497 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,576 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,062 views
0 votes
1 answer

Not able to access kubernetes api from a pod in azure

Follow these steps Add --bind-address=0.0.0.0 option to the line https://github.com/kubernetes/kubernetes/blob/v1.2.0/docs/getting-started-guides/coreos/azure/cloud_config_templates/kubernetes-cluster-main-nodes-template.yml#L218  Created ...READ MORE

answered Aug 30, 2018 in Kubernetes by Kalgi
• 52,350 points
1,034 views
0 votes
1 answer

Pods IP address from inside a container in the pod

Make sure that your pod yaml file ...READ MORE

answered Aug 29, 2018 in Kubernetes by Kalgi
• 52,350 points
2,475 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP