How do I keep a Kubernetes pod running with no http endpoint? (prevent back-off)

12/30/2021

I have a usecase where (at least for now) I need a k8s pod to stay up without a HTTP or TCP endpoint. I tried the following deployment...

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: node-deployment
  labels:
    app: node-app
spec: 
  selector: 
    matchLabels:
      app: node-app
  template:
    metadata:
      labels:
        app: node-app
    spec:
      containers:
      - name: node-server
        image: node:17-alpine
        exec:
            command: ["node","-v"]
        livenessProbe:
          exec:
            command: ["node","-v"]
          initialDelaySeconds: 5
          periodSeconds: 5  
        readinessProbe:
          exec:
            command: ["node","-v"]
          initialDelaySeconds: 5
          periodSeconds: 5  

But after a while it stops the pod with the following error...

Warning BackOff 5s (x10 over 73s) kubelet, minikube Back-off restarting failed container

And the pod status shows...

node-deployment-58445f5649-z6lkz 0/1 CrashLoopBackOff 5 (103s ago) 4m47s

I know it is running because I see the version in kubectl logs <node-name>. How do I get the image to stay up with no long running process? Is this even possible?

-- Jackie
kubernetes
node.js

1 Answer

12/30/2021

The process of the container simply exited, the same happens if you run node -v in your terminal.

Not sure if the use case you provide is your real use case ( I can't see any reason to have the node version as an application), so ..

if you really want to have the version, you can change the command to be

["watch","-n1","node","-v"]

So it will print the node version every second

-- Christophe Willemsen
Source: StackOverflow