K8s Statefulset DNS
K8s Statefulset DNS
我正在制作自定义 REDIS StatefulSet yaml。到目前为止,我已经成功部署了应用程序,但 REDIS SLAVE 出现了问题。找不到高手,我也不是在猜测DNS配置错误的原因
我的 StatefulSet 看起来像这样:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-server
namespace: scm
labels:
app.k8s/name: redis
app.k8s/instance: server
spec:
replicas: 3
serviceName: redis-server
selector:
matchLabels:
app.k8s/name: redis
app.k8s/instance: server
template:
metadata:
labels:
app.k8s/name: redis
app.k8s/instance: server
spec:
containers:
- name: redis-server
image: redis:6.0.9-alpine
imagePullPolicy: IfNotPresent
command: ["redis-server", "/data/conf/redis.conf"]
ports:
- name: redis
containerPort: 6379
和一个看起来像这样的无头服务:
apiVersion: v1
kind: Service
metadata:
name: redis-server-headless
namespace: scm
labels:
app.k8s/name: redis
app.k8s/instance: server
app.k8s/part-of: gitlab
spec:
type: ClusterIP
clusterIP: None
publishNotReadyAddresses: true
ports:
- name: server
port: 6379
protocol: TCP
targetPort: redis
selector:
app.k8s/name: redis
app.k8s/instance: server
当我执行 nslookup redis-server-headless
时,我可以找到 IP 地址,但是当我尝试 ping redis-server-0.redis-server-headless
或 ping redis-server-0.redis-server
时,我收到错误的地址错误消息。
我错过了什么?
你的 serviceName
off of redis statefulset 应该是 redis-server-headless
.
我正在制作自定义 REDIS StatefulSet yaml。到目前为止,我已经成功部署了应用程序,但 REDIS SLAVE 出现了问题。找不到高手,我也不是在猜测DNS配置错误的原因
我的 StatefulSet 看起来像这样:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-server
namespace: scm
labels:
app.k8s/name: redis
app.k8s/instance: server
spec:
replicas: 3
serviceName: redis-server
selector:
matchLabels:
app.k8s/name: redis
app.k8s/instance: server
template:
metadata:
labels:
app.k8s/name: redis
app.k8s/instance: server
spec:
containers:
- name: redis-server
image: redis:6.0.9-alpine
imagePullPolicy: IfNotPresent
command: ["redis-server", "/data/conf/redis.conf"]
ports:
- name: redis
containerPort: 6379
和一个看起来像这样的无头服务:
apiVersion: v1
kind: Service
metadata:
name: redis-server-headless
namespace: scm
labels:
app.k8s/name: redis
app.k8s/instance: server
app.k8s/part-of: gitlab
spec:
type: ClusterIP
clusterIP: None
publishNotReadyAddresses: true
ports:
- name: server
port: 6379
protocol: TCP
targetPort: redis
selector:
app.k8s/name: redis
app.k8s/instance: server
当我执行 nslookup redis-server-headless
时,我可以找到 IP 地址,但是当我尝试 ping redis-server-0.redis-server-headless
或 ping redis-server-0.redis-server
时,我收到错误的地址错误消息。
我错过了什么?
你的 serviceName
off of redis statefulset 应该是 redis-server-headless
.