Is it possible to use a bash script to do the liveness test in pod?

4/2/2019

I'm currently setting up a kubernetes cluster with 3 nodes on 3 differents vm and each node is composed of 1 pod witch run the following docker image: ethereum/client-go:stable

The problem is that I want to do a health check test using a bash script (because I have to test a lot of things) but I don't understand how I can export this file to each container that are deployed with my yaml deployment file.

I've tried to add wget command in the yaml file to download my health check script from my github repo but it wasn't very clean from my point of view, maybe there is an other way ?

My current deployment file:

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

I expect to put health check script in /test/health.sh

Any ideas ?

-- yatsukino
kubernetes

3 Answers

4/2/2019

If you're using helm look at chart tests: https://github.com/helm/helm/blob/master/docs/chart_tests.md. This covers readinessProbe tho, not liveness.

For advanced liveness probe, I'd run some kind of healthcheck sidecar which does all the advanced tests continiosly via localhost, and exposes a single /healthcheck endpoint. Then use the endpoint in a liveness probe.

-- Max Lobur
Source: StackOverflow

4/2/2019

This could be a perfect usecase for the init container, As there could be different images for the init container and the Application container thus they have different file system inside the pods, therefore we need to use Emptydir in order to share the state.

for further detail follow the link init-containers

-- Suresh Vishnoi
Source: StackOverflow

4/2/2019

Thanks to Suresh Vishnoi:

A way to resolve my problem is to use init container this way:

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: {}

The downloaded file will be visible in /test/health.sh

-- yatsukino
Source: StackOverflow