Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

kubernetes - How to terminate janusgraph container in case any exception is thrown

I'm using janusgraph docker image - https://hub.docker.com/r/janusgraph/janusgraph In my kubernetes deployment to initialise the remote graph using groovy script mounted to docker-entrypoint-initdb.d

This works as expected but in case if the remote host is not ready the janusgraph container throws exception and is still in the running mode.

Because of this kubernetes will not attempt to restart the container again. Is there any way so that I can configure this janusgraph container to terminate in case of any exception

question from:https://stackoverflow.com/questions/65907261/how-to-terminate-janusgraph-container-in-case-any-exception-is-thrown

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As @Gavin has mentioned you can use probes to check if containers are working. Liveness Probes is used to know when containers are failed. If a container is unresponsive - it can restart the container.

Readiness probes inform when the container is available for accepting traffic. The readiness probe is used to control which pods are used as the backends for a service. A pod is considered ready when all of its containers are ready. If a pod is not ready, it is removed from service Endpoints.

Kubernetes supports three mechanisms for implementing liveness and readiness probes:

1) making an HTTP request against a container This probes have additional fields that can be set on httpGet:

  • host: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead.
  • scheme: Scheme to use for connecting to the host (HTTP or HTTPS). Defaults to HTTP.
  • path: Path to access on the HTTP server. Defaults to /.
  • httpHeaders: Custom headers to set in the request. HTTP allows repeated headers.
  • port: Name or number of the port to access on the container. Number must be in the range 1 to 65535.

Read more: http-probes.

livenessProbe:
  httpGet:
    path: /healthz
    port: liveness-port

2) opening a TCP socket against a container

initialDelaySeconds: 15  
livenessProbe: ~  
periodSeconds: 20  
port: 8080  
tcpSocket: ~

3) running a command inside a container

livenessProbe:  
  exec:  
    command:  
    - sh  
    - /tmp/status_check.sh  
  initialDelaySeconds: 10  

If you will get status code different than 0 this will mean that probe failed. You can also add to probes additional params such as initialDelaySeconds: indicate number of seconds after the container has started before liveness or readiness probes are initiated. See: configuring-probes.

In every case add also restartPolicy: Never to your pods definition. By default is always.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...