How to access kubernetes cluster using masterurl

3/23/2020

I am trying to connect to kubernetes cluster using master url. However, I encounter an error when attempting the following command

Command: config, ConfigErr clientcmd.BuildConfigFromFlags("https://192.168.99.100:8443","")

Error: Get "https://192.168.99.100:8443/api/v1/namespaces": x509: certificate signed by unknown authority

Has anyone else encountered this and/or know how to solve this error?

-- Pattapu Sai
kubernetes
kubernetes-go-client

2 Answers

3/23/2020
config, ConfigErr = clientcmd.BuildConfigFromFlags(masterurl,"")
        config.BearerToken=token
        config.Insecure=true

use this code to make it work.it worked for me

-- Pattapu Sai
Source: StackOverflow

3/23/2020

Get the kube-apiserver endpoint by describing the service

kubectl describe svc kubernetes

This will list the endpoint for your APIServer like this:

Endpoints:         172.17.0.6:6443

Get the token to access the APIServer like this:

TOKEN=$(kubectl get secret $(kubectl get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )

Query the APIServer with the retreived token:

curl -v https://172.17.0.6:6443/api/v1/nodes -k  --header "Authorization:Bearer $TOKEN" --insecure
-- piy26
Source: StackOverflow