是否可以使用bash脚本在pod中进行活动性测试?

时间:2019-04-02 11:32:24

标签: kubernetes

我目前正在3个不同的虚拟机上设置一个具有3个节点的kubernetes集群,每个节点由1个Pod Witch组成,运行以下docker镜像:ethereum / client-go:stable

问题是我想使用bash脚本进行运行状况检查测试(因为我必须测试很多东西),但我不知道如何将这个文件导出到与我一起部署的每个容器中yaml部署文件。

我尝试在yaml文件中添加wget命令以从github存储库下载我的健康检查脚本,但是从我的角度来看这不是很干净,也许还有另一种方法? / p>

我当前的部署文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: goerli
  name: goerli-deploy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: goerli
  template:
    metadata:
      labels:
        app: goerli
    spec:
      containers:
        - image: ethereum/client-go:stable
          name: goerli-geth
          args: ["--goerli", "--datadir", "/test2"]
          env:
          - name: LASTBLOCK
            value: "0"
          - name: FAILCOUNTER
            value: "0"
          ports:
          - containerPort: 30303
            name: geth
          livenessProbe:
            exec:
              command:
              - /bin/sh
              - /test/health.sh
            initialDelaySeconds: 60
            periodSeconds: 100
          volumeMounts:
          - name: test
            mountPath: /test
      restartPolicy: Always
      volumes:
      - name: test
        hostPath:
          path: /test

我希望将运行状况检查脚本放入/test/health.sh

有什么想法吗?

3 个答案:

答案 0 :(得分:2)

这对于init容器可能是一个完美的用例,因为init容器和Application容器可能会有不同的映像,因此它们在pod内具有不同的文件系统,因此我们需要使用 Emptydir 以共享状态。

有关更多详细信息,请点击链接init-containers

答案 1 :(得分:1)

感谢Suresh Vishnoi:

解决我的问题的一种方法是使用init容器:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: goerli
  name: goerli-deploy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: goerli
  template:
    metadata:
      labels:
        app: goerli
    spec:
      containers:
        - image: ethereum/client-go:stable
          name: goerli-geth
          args: ["--goerli", "--datadir", "/test2"]
          env:
          - name: LASTBLOCK
            value: "0"
          - name: FAILCOUNTER
            value: "0"
          ports:
          - containerPort: 30303
            name: geth
          livenessProbe:
            exec:
              command:
              - /bin/sh
              - /test/health.sh
            initialDelaySeconds: 60
            periodSeconds: 100
          volumeMounts:
          - name: test
            mountPath: /test
      initContainers: 
      - name: healthcheck
        image: ethereum/client-go:stable
        command: ["wget", "-O", "/test2/health.sh", "https://My-script-bash"]
        volumeMounts:
        - name: test
          mountPath: "/test"
      restartPolicy: Always
      volumes:
      - name: test
        emptyDir: {}

下载的文件将显示在/test/health.sh

答案 2 :(得分:0)

如果您使用头盔,请查看图表测试:https://github.com/helm/helm/blob/master/docs/chart_tests.md。这涵盖了准备就绪的问题,而不是活力。

对于高级活动性探针,我将运行某种healthcheck sidecar,它通过localhost连续进行所有高级测试,并公开单个/healthcheck端点。然后在活动性探针中使用端点。