How can I ping a password protected Redis server using netcat in an initContainer?

2/7/2020

Note: solution can use netcat or any other built-in Linux utility

I need to implement an initContainer and liveness probe that confirms my redis pod is up for one of my redis dependent pods. I have attempted the netcat solution offered as the answer here ((printf "PING\r\n"; sleep 1) | nc 10.233.38.133 6379) but I get -NOAUTH Authentication required. error in response. Any way around this? I am aware I could install redis-cli or make a management command in my Django code but would prefer not to. Nor do I want to implement a web server for my Redis instance and use curl command.

-- bbmhmmad
kubernetes
kubernetes-pod
linux
netcat
redis

1 Answer

2/7/2020

You could always send in your AUTH command as part of your probe, like:

`"AUTH ....\r\nPING\r\n"`

Unless you're getting INFO from the server, you don't seem to care about the nature of the response, so no auth is required, just test for NOAUTH.

-- tadman
Source: StackOverflow