如何在Docker容器中操作k8s集群

时间:2020-05-04 00:43:40

标签: docker kubernetes kubectl kubeconfig

docker容器 running on a docker machine instead of a k8s pod如何操作k8s集群。例如,如果我需要在容器内执行以下操作:

kubectl获得豆荚

在我的dockerfile中,我安装了kubectl

RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN sudo mv ./kubectl /usr/local/bin/kubectl

当我运行kubectl get pods时,结果如下:

kubectl get pod
error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

因此,我在config命令中将docker run安装到了Docker容器中

docker run -v /root/.kube/config:/root/.kube/config my-images

结果如下:

kubectl get pod
Error in configuration: 
* unable to read client-cert /root/.minikube/profiles/minikube/client.crt for minikube due to open /root/.minikube/profiles/minikube/client.crt: no such file or directory
* unable to read client-key /root/.minikube/profiles/minikube/client.key for minikube due to open /root/.minikube/profiles/minikube/client.key: no such file or directory
* unable to read certificate-authority /root/.minikube/ca.crt for minikube due to open /root/.minikube/ca.crt: no such file or directory

这似乎是由于k8s配置文件中的current-context: minikube

然后再次装入身份验证文件,它运行成功。

现在,我在挂载kubectl get pods时可以调用otherwise命令或-v /root/.kube/config:/root/.kube/config -v /root/.minikube/:/root/.minikube/在容器外部操作集群,但是,此不适用于集群挂载kubeadm or otherwise创建。

但是我希望能够以统一的方式 将所需的配置文件等安装到容器中,以便我可以使用相同的命令来操作由minikuberancher k3skubeadm创建的k8s集群

总而言之,我想针对k8s集群的所有情况(例如-v file: file -v dir:dir实施操作)安装一组统一的文件或目录以任何方式创建的k8s集群上,例如获取pod状态,创建,删除各种类型的资源等等

我需要获得在k8s上进行操作的最大权限

有人可以告诉我我需要做什么吗?

0 个答案:

没有答案