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

问题描述 投票:0回答:1

在我们的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

consul.d文件夹中,我们已经静态定义了我们的服务。它可以与docker-compose一起正常工作。

但是当尝试使用此configmap在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 ...

和领事.yaml:

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: ["agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=/consul/conf/"]
      volumes:
        - name: config-volume
          configMap:
            name: consul-config

我遇到以下错误:

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

但是当我运行没有command: agent...的容器并对其进行重击时,我可以列出安装在正确位置的文件。尽管该文件夹存在,为什么领事给我一个未发现的错误?

kubernetes consul
1个回答
1
投票

到窗格中的execute command,您必须在command字段中定义命令,并在args字段中定义该命令的参数。 command字段与Docker中的ENTRYPOINT相同,args字段与CMD相同。在这种情况下,可以将/bin/sh定义为ENTRYPOINT,将"-c, "consul agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -data-dir=/bitnami/consul/data/ -config-dir=/consul/conf/"定义为参数,以便可以执行consul 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
© www.soinside.com 2019 - 2024. All rights reserved.