reference resources
https://kubernetes.io/zh/docs/tasks/run-application/access-api-from-pod/
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
clusterrolebinding.rbac.authorization.k8s.io/permissive-binding created
Then let’s try