使用特定命令启动 kubernetes 容器 [英] Start kubernetes container with specific command
问题描述
使用fleet,我可以指定在容器启动时在容器内运行的命令.使用 Kubernetes 似乎也应该很容易实现这一点,但我似乎找不到任何说明如何操作的内容.似乎您必须专门创建容器才能使用某个命令启动.
Using fleet I can specify a command to be run inside the container when it is started. It seems like this should be easily possible with Kubernetes as well, but I can't seem to find anything that says how. It seems like you have to create the container specifically to launch with a certain command.
拥有一个通用容器并使用不同的参数启动它比为特定情况创建许多不同的容器或设置和获取环境变量要简单得多.
Having a general purpose container and launching it with different arguments is far simpler than creating many different containers for specific cases, or setting and getting environment variables.
是否可以指定 Kubernetes pod 在启动时在 Docker 镜像中运行的命令?
Is it possible to specify the command a kubernetes pod runs within the Docker image at startup?
推荐答案
我花了 45 分钟来寻找这个.然后我发布了一个关于它的问题,并在 9 分钟后找到了解决方案.
I spend 45 minutes looking for this. Then I post a question about it and find the solution 9 minutes later.
在 Cassandra example 中有我想要的提示.图像下方的 command
行:
There is an hint at what I wanted inside the Cassandra example. The command
line below the image:
id: cassandra
kind: Pod
apiVersion: v1beta1
desiredState:
manifest:
version: v1beta1
id: cassandra
containers:
- name: cassandra
image: kubernetes/cassandra
command:
- /run.sh
cpu: 1000
ports:
- name: cql
containerPort: 9042
- name: thrift
containerPort: 9160
env:
- key: MAX_HEAP_SIZE
value: 512M
- key: HEAP_NEWSIZE
value: 100M
labels:
name: cassandra
尽管找到了解决方案,但如果 Kubernetes 项目中有明显的地方我可以看到各种配置文件(pod、服务、复制控制器)的所有可能选项,那就太好了.
Despite finding the solution, it would be nice if there was somewhere obvious in the Kubernetes project where I could see all of the possible options for the various configuration files (pod, service, replication controller).
这篇关于使用特定命令启动 kubernetes 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!