I need to delete some keys in my redis cluster which can only be accessed from a jump machine deployed in the kubernetes cluster.
So if I know the key I can delete it by the following command without problem:
➜ kubectl exec -it jump-machine -- /usr/local/bin/redis-cli -c -h redis-cluster-host DEL "the-key"
(interger) 1
But if I want to do it in batch then it gives output 0 which means not deleted:
➜ kubectl exec -it jump-machine -- /usr/local/bin/redis-cli -c -h redis-cluster-host --scan --pattern "*the-key-pattern*" | xargs -L 1 kubectl exec -it jump-machine -- /usr/local/bin/redis-cli -c -h redis-cluster-host -c DEL
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
I'm quite new about using the xargs
, and I can't tell where is wrong.
I tried debug it with the following command, it gives all the keys without issue:
➜ kubectl exec -it jump-machine -- /usr/local/bin/redis-cli -c -h redis-cluster-host --scan --pattern "*the-key-pattern*" | xargs -L 1 echo
the-key-pattern-1
the-key-pattern-2
the-key-pattern-3
...
Hope someone can shed some light on it, thanks in advance!
ssh -t
... In different cases [ 1, 2] such behavior was attributable to the non-allocation of a pseudo tty...alias kubectl='winpty kubectl'
... so again in the same direction -- allocate a paseudo tty. I do not know the semantic of the command you are using, but you can try a workaround executing abash
(with a forced tty allocation) that executes your command(s).bash
get the same result.