How to configure readiness and liveness probe of pod in kubernetes, where a standalone go service is running?

8/7/2020

I have written a job scheduler service in go, which uploads files under a periodic interval. There is no HTTP service is running inside that service.

Normally, for HTTP service, below are liveness and readiness probe configuration, need to be added at the deployment file.

readinessProbe:
  httpGet:
    path: <http_get_path>
    port: 3401
  initialDelaySeconds: 5
  timeoutSeconds: 1
  periodSeconds: 15

livenessProbe:
  httpGet:
    path: <http_get_path>
    port: 3401
  initialDelaySeconds: 15
  timeoutSeconds: 1
  periodSeconds: 15

For standalone service like below:

//main : main function to trigger the services
func main() {
	scheduler.RunScheduler()
}

//RunScheduler : Run the scheduler
func RunScheduler() {
	done := make(chan bool)
	quit := make(chan bool)

	go startJob1()

	go startJob2()
    
	sigs := make(chan os.Signal, 1)
	//pass done "True", only if the application is stopped
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
	<-sigs
    .....
}

which just runs periodically and don't listen to any port, can we configure any kind of readiness probe and liveness probe?

-- Siddhanta Rath
go
kubernetes
kubernetes-pod

1 Answer

8/7/2020

Since your container doesn't handle any http request you dont need readinessProbe.

readinessProbe: Indicates whether the container is ready to respond to requests. If the readiness probe fails, the endpoints controller removes the Pod's IP address from the endpoints of all Services that match the Pod.

When should you use a liveness probe?

You need a livenessProbe.

livenessProbe: Indicates whether the container is running. If the liveness probe fails, the kubelet kills the container, and the container is subjected to its restart policy.

When should you use a readiness probe?

Here is an example with ps of process:

livenessProbe:
    exec:
     command:
     - ps -ef | grep my_process_name
    initialDelaySeconds: 120
    periodSeconds: 30

Be sure you have a ps command in the $PATH.

Another way is to create a file in the tmp dir on the pod start and check if a file present in the exec command.

-- Philidor
Source: StackOverflow