How to access Kubernetes API when using minkube?

11/21/2016

What is correct way to kubernetes cluster setup using minikube through the kubernetes api ? At the moment, I can't find a port through which the kubernetes cluster can be accessed.

-- KarateKid
kubernetes
minikube

4 Answers

2/9/2020

These instructions worked for me https://github.com/jenkinsci/kubernetes-plugin#configuration-on-minikube

Needed to generate & upload pfx file, along with the other steps mentioned there.

-- ObjectNameDisplay
Source: StackOverflow

9/13/2017

The easiest way to access the Kubernetes API with when running minikube is to use

kubectl proxy --port=8080

You can then access the API with

curl http://localhost:8080/api/

This also allows you to browse the API in your browser. Start minikube using

minikube start --extra-config=apiserver.Features.EnableSwaggerUI=true

then start kubectl proxy, and navigate to http://localhost:8080/swagger-ui/ in your browser.

You can access the Kubernetes API with curl directly using

curl --cacert ~/.minikube/ca.crt --cert ~/.minikube/client.crt --key ~/.minikube/client.key https://`minikube ip`:8443/api/

but usually there is no advantage in doing so. Common browsers are not happy with the certificates minikube generates, so if you want to access the API with your browser you need to use kubectl proxy.

-- Sven Marnach
Source: StackOverflow

11/21/2016

Running minikube start will automatically configure kubectl.

You can run minikube ip to get the IP that your minikube is on. The API server runs on 8443 by default.


Update: To access the API server directly, you'll need to use the custom SSL certs that have been generated. by minikube. The client certificate and key are typically stored at: ~/.minikube/apiserver.crt and ~/.minikube/apiserver.key. You'll have to load them into your HTTPS client when you make requests.

If you're using curl use the --cert and the --key options to use the cert and key file. Check the docs for more details.

-- iamnat
Source: StackOverflow

2/21/2018

I went through lots of answers, but lots of them are wrong.

Before we do, we need IP and token.

How to get IP: minikube ip How to generate Token:

$export secret=kubectl get serviceaccount default -o json | jq -r '.secrets[].name'

$kubectl get secret $secret -o yaml | grep "token:" | awk {'print $2'} |  base64 -D > token

Note: base64 uses -D for mac, but -d for Linux.

Then, the correct command is:

#curl -v -k -H --cacert ~/.minikube/ca.crt -H "Authorization: Bearer $(cat ~/YOUR_TOKEN)"  "https://{YOUR_IP}:8443/api/v1/pods"
-- xichen
Source: StackOverflow