kubernetes integration with python

9/6/2019

How to get the list of namespace in kubernetes with RBAC enable using Python.

I have configured kubernetes in my windows and i have config file with cluster info . After running kubectl proxy , I am able to launch UI dashboard .It requires token and once i added the access token , I am able to fetch namespace and pod details .Once after token expired in 60 minutes .

Again ,UI dashboard is asking new token details.Once I provided new access token,it gives

403 unauthorized error.

Can someone help me why my new access token is not recognized

Access the namespace , pods after giving new access token

-- Prabhu B
kubernetes
python

3 Answers

9/6/2019

If you want to access the Kubernetes API from inside the pod, you can create a service account and grant access to that account.

Further you can use code similar to :

    import kubernetes, os, sys
    kubernetes.config.load_incluster_config()


    v1 = kubernetes.client.CoreV1Api()
-- nimit garg
Source: StackOverflow

9/6/2019

The access token is typically associated with a Service Account. It may be that the service account that you used initially doesn't exist anymore.

It may be that you are using a Bootstrap Token that looks something like this: 781292.db7bc3a58fc5f07e if that's the case, these expire after 60 minutes and you will have to generate a new one. Assuming you created your cluster with kubeadm you can regenerate it like this:

$ kubeadm token generate
-- Rico
Source: StackOverflow

9/6/2019

In order to access K8s resources, it better to create Service Account, get the token and access. For example, take a look at this Service Account manifest file, specify necessary RoleBinding/ClusterRolebinding and create Service Account

Once done, use this shell script to generate kubeconfig file which contains your service account token(which was created in earlier step)

Use that kubeconfig file to access kubernetes resources programmatically

-- Veerendra Kakumanu
Source: StackOverflow