interacting with redis-client pod on kubernetes

3/25/2019

I'm having a Redis cluster on Kubernetes.

I need to interact with one of the redis-client pods, mainly in order to delete keys from time to time.

The way I'm currently doing it is:

  1. Tunnel Kubernetes dashobard to localhost:8081

  2. From the dashboard, doing exec into redis client pod

  3. Running: redis-cli -h redis-master -a mypassword

  4. Deleting the needed key, del "*my_key_name*"

I want to be able to do so from a local python script. Using kubernetes for python I'm able to execute commands on redis-client pod:

    v1=client.CoreV1Api()
    exec_command = [
    '/bin/sh',
    '-c',
    'redis-cli -h redis-master -a mypassword']

    resp = stream(v1.connect_get_namespaced_pod_exec,"redis-client2-5889976c9b-nv99v", 'default',
              command=exec_command,
              stderr=True, stdin=False,
              stdout=True, tty=False)

My problem is, I can't execute commands in the context of redis-cli, i.e, I can connect to redis-cli but can't send commands to it (only to /bin/sh)

Is there a way to do what I want?

Thanks

-- Noam
kubernetes
python-2.7
redis-cli
redis-cluster

1 Answer

3/25/2019

Ok so the apparently the solution is pretty simple, I can pass parameters to the redis-cli tool to execute what I want, all in one command. so I did:

exec_command = [
'/bin/sh',
'-c',
'redis-cli -h redis-master -a mypassword del *my_key_name*']

and that is it

-- Noam
Source: StackOverflow