1

I want to start a container and directly run redis-cli interactively inside. For some reason, in my attempts, the input is always ignored.

Launching an interactive shell and then launching the program manually works:

# in my local shell:
$ kubectl run redis-cli --image redis:latest --attach --leave-stdin-open --rm -it --command -- bash
# then in container shell:
root@redis-cli:/data# redis-cli -h redis.example.com
# now the redis-cli shell is open:
redis.example.com:6379>

How do I combine this into one command that brings me directly into the redis-cli shell? I've tried the following, but I see no prompt and all my input is ignored. I can't even ctrl-C or ctrl-D out of it.

kubectl run redis-cli2 --image redis:latest --attach --leave-stdin-open --rm -it --command -- redis-cli -h redis.example.com --stat
# or
kubectl run redis-cli2 --image redis:latest --attach --leave-stdin-open --rm -it --command -- bash -ic -- "redis-cli -h redis.example.com --stat"

If I do a --stat, I see command output. If I do a ping, I see the ping arrive at the Redis server (using monitor from another container) but I never see any output and the pod goes into CrashLoopBackOff before terminating.

At this point, I'm not sure if this behavior is specific to redis-cli or the redis image or if this behavior is the same for other interactive programs (well, at least bash seems to work as expected).

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Balz Guenat
  • 1,552
  • 2
  • 15
  • 35
  • What image/deployment is used for redis itself? To have minimal reproducible example. – moonkotte Aug 30 '21 at 15:22
  • 1
    In my case, it's an AWS ElastiCache instance, but I don't expect it to matter. Running the Redis server in the same k8s cluster is probably easier way to reproduce the situation. – Balz Guenat Aug 31 '21 at 16:59
  • 1
    Well, I saw what you said, I tried adding verbosity level to max with `--v=9`, pod is scheduled and waits for something else. Moreover if you press like 31 times on any keys, it will show you the prompt. Same happens to another image with `redis-cli`. Not sure why. – moonkotte Sep 01 '21 at 14:49
  • 1
    By the way what version of `kubectl` and cluster is used? It may have different behaviour – moonkotte Sep 02 '21 at 20:56

1 Answers1

5

Posting this as a community wiki, feel free to edit and expand


I found a workaround, most likely this is related to redis-cli container and its implementation. The same behaviour is observed with different image of redis-cli - docker.io/bitnami/redis:6.2.5-debian-10-r34

When the command from question is run, after pod is created redis-cli, this message is shown:

$ kubectl run redis-cli3 --image redis:latest --attach --leave-stdin-open --env REDIS_PASSWORD=$REDIS_PASSWORD --rm -it -- redis-cli -h redis-master -a $REDIS_PASSWORD
If you don't see a command prompt, try pressing enter.

It should get enter as a key, but it doesn't work.

Surprisingly shift + r combination is accepted and shows redis-cli connected.

moonkotte
  • 3,661
  • 2
  • 10
  • 25
  • Can confirm, `shift + r` brings up the prompt. Can you explain why this works? – Balz Guenat Sep 07 '21 at 11:34
  • @BalzGuenat Unfortunately I don't know, this is the reason why I made this workaround as community wiki in hope that someone can actually add this to my answer or add their one. However I think this should be addressed to `redis-cli` app developers so they can trace what where and why. – moonkotte Sep 07 '21 at 13:18
  • I would like to know this too. I see similar things with the output not displaying for containers like busybox when attempting to use telnet (but strangely the output shows up in `kubectl logs`..). `shift + r` trick unfortunately doesn't work for busybox like it does with the redis container.. – skupjoe Mar 12 '22 at 03:15
  • Really curious about how/why `shift + r` works. There's no way I would have figured this out - thanks for sharing the solution! – Dwight Gunning Aug 04 '22 at 21:20