Kubernetes - 如何在容器内运行kubectl命令? [英] Kubernetes - How to run kubectl commands inside a container?

查看:1987
本文介绍了Kubernetes - 如何在容器内运行kubectl命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在pod中的容器中,如何使用kubectl运行命令?例如,如果我需要在容器内做这样的事情:

In a container inside a pod, how can I run a command using kubectl? For example, if i need to do something like this inside a container:


kubectl get pods

kubectl get pods

我已经尝试过:在我的docker文件中,我有这些命令:

I have tried this : In my dockerfile, I have these commands :

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




编辑:我正在尝试OSX文件,我已经将其更正为linux二进制文件。 (由@svenwltr修正

EDIT : I was trying the OSX file, I have corrected it to the linux binary file. (corrected by @svenwltr

在创建docker文件时,这是成功的,但是当我运行kubectl将pod放在容器内时,

While creating the docker file, this is successful, but when I run the kubectl get pods inside a container,

kubectl get pods

我收到此错误:


与服务器的连接:被拒绝 - 您是否指定了正确的主机或端口?

The connection to the server : was refused - did you specify the right host or port?

当我在本地部署时,如果我的docker机器没有运行,但是在容器内部,我遇到这个错误一台码头机器正在运行?

When I was deploying locally, I was encountering this error if my docker-machine was not running, but inside a container how can a docker-machine be running?

本地,我通过运行以下命令来解决这个错误:
(dev是docker-machine的名称)

Locally, I get around this error by running the following commands: (dev is the name of the docker-machine)

docker-machine env dev
eval $(docker-machine env dev)

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

Can someone please tell me what is it that I need to do?

推荐答案

我会使用kubernetes api,你只需要insta卷曲,而不是 kubectl ,其余的是安静的。

I would use kubernetes api, you just need to install curl, instead of kubectl and the rest is restful.

curl http://localhost:8080/api/v1/namespaces/default/pods

在我的一个apitorver。将 localhost 更改为 apiserver ip address / dns name

Im running above command on one of my apiservers. Change the localhost to apiserver ip address/dns name.

根据您的配置,您可能需要使用ssl或提供客户端证书。

Depending on your configuration you may need to use ssl or provide client certificate.

为了找到api端点,您可以使用 - v = 8 code> kubectl 。

In order to find api endpoints, you can use --v=8 with kubectl.

示例:

kubectl get pods --v=8

资源:

Kubernetes API文档

Kubernetes API documentation

这篇关于Kubernetes - 如何在容器内运行kubectl命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆