use kubectl in a pod

reference resources

In some cases, we would like to use kubectl to operate the cluster in a pod, for example

In Argo workflow, a task is required, and kubectl can be called to modify some resources

Method 1

The stupidest way is to mount kubeconfig yaml file. In this case, you use the user in config file, which will not be discussed here, because this way is too stupid

Method 2

Use kubectl image, and then assign RBAC permission to pod, so that pod can operate the cluster through the service account bound by RBAC

The image used is bitnami/kubectl
The entrypoint used is /bin/bash

Try to get cluster information through kubectl get nodes

Directly add a cluster level admin role to the default Sa of the namespace

kubectl create clusterrolebinding permissive-binding --clusterrole=cluster-admin --group=system:serviceaccounts:lizhe created

Then let’s try

Send a Message