Fake liveness/readiness probe in kubernetes

3/13/2019

Is it possible to fake a container to always be ready/live in kubernetes so that kubernetes thinks that the container is live and doesn't try to kill/recreate the container? I am looking for a quick and hacky solution, preferably.

-- user674669
kubernetes

1 Answer

3/15/2019

Liveness and Readiness probes are not required by k8s controllers, you can simply remove them and your containers will be always live/ready.

If you want the hacky approach anyways, use the exec probe (instead of httpGet) with something dummy that always returns 0 as exit code. For example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        livenessProbe:
          exec:
            command:
            - touch
            - /tmp/healthy
        readinessProbe:
          exec:
            command:
            - touch
            - /tmp/healthy
-- Eduardo Baitello
Source: StackOverflow