You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes精细并行处理教程Redis连接问题求助

Fix: Could not connect to Redis at redis:6379: Name or service not known

Hey there, let's get this sorted out quickly! The root cause of your DNS resolution error is that Kubernetes DNS resolves Service names, not Pod names. When you ran redis-cli -h redis, you were trying to reach a Service named redis—but you only created a Pod named temp, with no corresponding Service to map that hostname to.

Here's how to fix it step by step:

1. Deploy Redis properly with a Service (per the tutorial)

The official guide expects you to set up a Redis Deployment and Service first, not just a one-off Pod. Run these commands first:

# Create a Redis Deployment to manage the Redis Pod
kubectl create deployment redis --image=redis

# Expose the Deployment as a Service so DNS can resolve "redis"
kubectl expose deployment redis --port=6379 --name=redis

2. Recreate your temp Pod and connect

Now that the redis Service exists, spin up your temporary Pod again:

kubectl run -i --tty temp --image redis --command "/bin/sh"

Once inside the Pod, run this command again—it should work now:

redis-cli -h redis

If you just want a quick test without setting up a Service, you can connect directly to the Pod's IP:

  • First, get the Pod's IP address:
kubectl get pod temp -o jsonpath='{.status.podIP}'
  • Then use that IP in redis-cli:
redis-cli -h <your-pod-ip-here>

Note: This is unstable because Pod IPs change when the Pod restarts—using a Service is the proper, production-ready way.

Why this happened

To clarify: Kubernetes DNS assigns a domain name to every Service in the format <service-name>.<namespace>.svc.cluster.local. When you use redis-cli -h redis, it automatically resolves to the redis Service's IP in your current namespace. Since you didn't have that Service created earlier, DNS had no record to look up, hence the error.

内容的提问来源于stack exchange,提问作者magladde

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:58:12