M
M
myasnik83522019-06-25 15:11:58
Kubernetes
myasnik8352, 2019-06-25 15:11:58

How to execute a command in a kubernetes container by condition?

The situation is as follows: there are two interconnected services (pods). The first one, when launched, takes the configuration file from the second service via http.
Periodically, the second service is rebuilt with an updated config, and the first service does not "know" anything about updating until it is restarted / recreated (manually or by http request).
After updating the second service, it is necessary to execute one command once, either restart / delete the first service, or http request.
k8s has init containers, but no post-init containers or anything like that. Readiness and livenessprobe are not suitable, because work constantly. I read about job and cronjob, but I'm not sure what will fit. Maybe someone faced a similar problem?
Deployment of services is carried out using gitlab-ci, it has different groups for each service with its own .gitlab-ci.yml

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Pugachev, 2019-06-27
@myasnik8352

myasnik8352
there is still one https://kubernetes.io/docs/concepts/containers/con...

M
myasnik8352, 2019-06-26
@myasnik8352

maybe it will come in handy for someone, added a second container with busybox and wget to deployment.yaml

containers: 
    - name: service2
      image: repo.local/service2:latest
      ports: 
      - containerPort: 80
    - name: restart-service1
      image: busybox
      command: ['sh', '-c', 'wget http://service1/restart; echo waiting for restart service1; sleep 2; tail -f /dev/null;']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question