Restart container within pod

前端 未结 9 1087
日久生厌
日久生厌 2020-12-04 07:04

I have a pod test-1495806908-xn5jn with 2 containers. I\'d like to restart one of them called container-test. Is it possible to restart a single co

相关标签:
9条回答
  • 2020-12-04 07:40

    We use a pretty convenient command line to force re-deployment of fresh images on integration pod.
    We noticed that our alpine containers all run their "sustaining" command on PID 5. Therefore, sending it a SIGTERM signal takes the container down. imagePullPolicy being set to Always has the kubelet re-pull the latest image when it brings the container back.

    kubectl exec -i [pod name] -c [container-name] -- kill -15 5
    
    0 讨论(0)
  • 2020-12-04 07:42

    The whole reason for having kubernetes is so it manages the containers for you so you don't have to care so much about the lifecyle of the containers in the pod.

    Since you have a deployment setup that uses replica set. You can delete the pod using kubectl delete pod test-1495806908-xn5jn and kubernetes will manage the creation of a new pod with the 2 containers without any downtime. Trying to manually restart single containers in pods negates the whole benefits of kubernetes.

    0 讨论(0)
  • 2020-12-04 07:45

    There are cases when you want to restart a specific container instead of deleting the pod and letting Kubernetes recreate it.

    Doing a kubectl exec POD_NAME -c CONTAINER_NAME /sbin/killall5 worked for me.

    (I changed the command from reboot to /sbin/killall5 based on the below recommendations.)

    0 讨论(0)
提交回复
热议问题