Command running in kubernetes hangs

Viewed 4100

I need to run a command in clickhouse database in kubernetes.

When I try it with docker it works ok:

docker run -it yandex/clickhouse-client -h 172.19.0.1 --database=test --query="SYSTEM RELOAD DICTIONARIES"

but when I run it in kub:

kubectl run  --quiet -it --rm  clickhouse-client --image=yandex/clickhouse-client -- -h clickhouse-server  --database=test --query="SYSTEM RELOAD DICTIONARIES"

Second command hangs. The pod is in CrashLoopBackOff with Back-off restarting failed container/ And the logs of container contains the result of query.

Why do the result not flushed to tty?

This command works for me:

kubectl run busybox --quiet -it --rm --restart=Never --image=busybox -- nslookup foobar

What is the difference with click-house client?

2 Answers

@ogbofjnr this is likely because the pod is getting killed as soon as your query is done. Kubernetes will restart the pod, and it will again die after executing the query. This is why you are seeing a restart loop.

For busy box, the entrypoint is a long running command like sleep 3600 https://github.com/kubernetes/kubernetes/blob/master/hack/testdata/recursive/pod/pod/busybox.yaml#L10-L12.

You should either try something similar or try Kubernetes cron job if the idea is to run the query on a schedule.

Your pod are being killed as soon it's running, I suggest you create your pod using file yaml and add command on in your yaml file then verify your clickhouse-server in DNS resolver

---
......
      containers:
      - name: clickhouse-client
        image: yandex/clickhouse-client
        command:
          - "-h"
          - "clickhouse-server"
          - "--database=test"
          - "--query='SYSTEM RELOAD DICTIONARIES'"
        resources: {}
........
---
Related