publishNotReadyAddresses

publishNotReadyAddresses 表示是否将没有就绪的 Pod 的地址关联到服务上。
默认情况是 false,只有就绪状态的 Pod 的地址才会关联到服务上。

创建 pod 资源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: Pod
metadata:
name: readiness-httpget-pod
namespace: default
labels:
app: myapp
env: test
spec:
containers:
- name: readiness-httpget-container
image: wangyanglinux/myapp:v1.0
imagePullPolicy: IfNotPresent
readinessProbe:
httpGet:
port: 80
path: /index1.html
initialDelaySeconds: 1
periodSeconds: 3

创建 svc 资源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
apiVersion: v1
kind: Service
metadata:
labels:
app: myapp
name: myapp
spec:
ports:
- name: 80-80
port: 80
protocol: TCP
targetPort: 80
selector:
app: myapp
type: ClusterIP

添加 publishNotReadyAddresses: true

1
$ kubectl patch service myapp -p '{"spec":{"publishNotReadyAddresses": true}}'