Kubernetes 使用config dir运行领事代理导致未找到异常

Kubernetes 使用config dir运行领事代理导致未找到异常,kubernetes,consul,Kubernetes,Consul,在docker-compose.yaml中,我们有: version: "3.5" services: consul-server: image: consul:latest command: "agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=./usr/src/app/consul.d/" volumes: - ./consul.d/:

在docker-compose.yaml中,我们有:

version: "3.5"
services:
  consul-server:
    image: consul:latest
    command: "agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=./usr/src/app/consul.d/"
    volumes:
      - ./consul.d/:/usr/src/app/consul.d
consur.d
文件夹中,我们静态地定义了我们的服务。它与docker compose配合使用效果良好

但当尝试使用此配置映射在Kubernetes上运行时:

ahmad@ahmad-pc:~$ kubectl describe configmap consul-config -n staging
Name:         consul-config
Namespace:    staging
Labels:       <none>
Annotations:  <none>

Data
====
trip.json:
----
... omitted for clarity ...
我得到了以下错误:

ahmad@ahmad-pc:~$ kubectl describe pod consul-server-7489787fc7-8qzhh -n staging
...

Error: failed to start container "consul-server": Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=/consul/conf/\": 
stat agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=/consul/conf/: 
no such file or directory": unknown
但是,当我在没有
命令:agent…
的情况下运行容器并猛击它时,我可以列出安装在正确位置的文件。 尽管文件夹存在,为什么领事仍给我一个未找到的错误?

要在pod中定义命令,您必须在
命令
字段中定义命令,并在
参数
字段中定义命令的参数<代码>命令字段与Docker中的
入口点
相同,
args
字段与
CMD
相同
在本例中,您将
/bin/sh
定义为入口点,并将
“-c,”consur-agent-server-bootstrap-ui-enable-script checks=true-client=0.0.0.0-data dir=/bitnami/consur/data/-config dir=/consur/conf/”
定义为参数,以便它可以执行
consur-agent…

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: consul-server
  name: consul-server
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: consul-server
  template:
    metadata:
      labels:
        io.kompose.service: consul-server
    spec:
      containers:
      - image: quay.io/bitnami/consul:latest
        name: consul-server
        ports:
        - containerPort: 8500
        env:
        - name: CONSUL_CONF_DIR # Consul seems not respecting this env variable
          value: /consul/conf/  
        volumeMounts:
        - name: config-volume
          mountPath: /consul/conf/
        command: ["bin/sh"]
        args: ["-c", "consul agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -data-dir=/bitnami/consul/data/ -config-dir=/consul/conf/"] 
      volumes:
        - name: config-volume
          configMap:
            name: consul-config

您是否尝试转换docker-compose.yaml.来转换您的文件!!谢谢,但我尝试了该工具,它生成了许多不必要的内容。我认为我转换正确,
命令
args
不是必须分开的,但是@KFC_的回答表明我错了。:)当我学习docker时,我我不认为将
命令
参数
分开是必要的。但现在我明白了!我无法想象
未找到目录
错误与这种分开有什么关系!你能解释一下吗?:)谢谢!
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: consul-server
  name: consul-server
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: consul-server
  template:
    metadata:
      labels:
        io.kompose.service: consul-server
    spec:
      containers:
      - image: quay.io/bitnami/consul:latest
        name: consul-server
        ports:
        - containerPort: 8500
        env:
        - name: CONSUL_CONF_DIR # Consul seems not respecting this env variable
          value: /consul/conf/  
        volumeMounts:
        - name: config-volume
          mountPath: /consul/conf/
        command: ["bin/sh"]
        args: ["-c", "consul agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -data-dir=/bitnami/consul/data/ -config-dir=/consul/conf/"] 
      volumes:
        - name: config-volume
          configMap:
            name: consul-config