这个task展示如何开启Istio CA健康检查。注意这是自从Istio V0.6之后的alpha功能。
自从Istio V0.6,Istio CA有一个可选开启的健康检查功能。默认情况,普通的Istio部署进程不开启这个功能。单签,健康检查功能可以通过定期向API发送CSRs探查CA CSR注册服务失败。很快将支持更多健康检查功能。
Istio CA包含一个prober client 模块,它定期检查CA的状态(当前只检查gRPC服务端的健康状态)。如果Istio CA是健康的,prober client 更新健康状态文件(这个文件总是空的)的修改时间。否则,它什么也不做。Istio CA依赖使用命令行的 K8s liveness and readiness probe 来检查pod上的健康状态文件的修改时间。如果文件在一个周期内没有更新,probe 将会触发, Kubelet 将会重启CA容器。
注意: 因为Istio CA健康检查目前仅监控CSR服务API的健康状态。如果生产安装不使用Istio Mesh Expansion (需要CSR服务API),则这个功能可以不需要。
Before you begin
- 安装Istio。注意在 installation steps 中的第5步开启身份认证。
Deploying the Istio CA with health check
部署开启健康检查的Istio CA。
kubectl apply -f install/kubernetes/istio-ca-with-health-check.yaml
部署 istio-ca
服务,这样CSR服务能够被健康检查器发现。
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Service
metadata:
name: istio-ca
namespace: istio-system
labels:
istio: istio-ca
spec:
ports:
- port: 8060
selector:
istio: istio-ca
EOF
Verifying the health checker is working
Istio CA将会记录健康检查结果。运行下列命令:
kubectl logs `kubectl get po -n istio-system | grep istio-ca | awk '{print $1}'` -n istio-system
你将看到类似输出:
...
2018-02-27T04:29:56.128081Z info CSR successfully signed.
...
2018-02-27T04:30:11.081791Z info CSR successfully signed.
...
2018-02-27T04:30:25.485315Z info CSR successfully signed.
...
上述日志表明周期的健康检查正在运行。可以看到健康检查间隔15s,这是默认的健康检查间隔时间。
(Optional)Configuring the health check
可选的调整健康检查配置来符合你的需求。打开文件install/kubernetes/istio-ca-with-health-check.yaml
, 然后查找下面几行。
...
- --liveness-probe-path=/tmp/ca.liveness # path to the liveness health check status file
- --liveness-probe-interval=60s # interval for health check file update
- --probe-check-interval=15s # interval for health status check
- --logtostderr
- --stderrthreshold
- INFO
livenessProbe:
exec:
command:
- /usr/local/bin/istio_ca
- probe
- --probe-path=/tmp/ca.liveness # path to the liveness health check status file
- --interval=125s # the maximum time gap allowed between the file mtime and the current sys clock.
initialDelaySeconds: 60
periodSeconds: 60
...
liveness-probe-path
and probe-path
是健康状态文件的路径,可以在Istio CA和prober配置; liveness-probe-interval
是更新健康状态文件的时间间隔,如果Istio CA是健康的话; probe-check-interval
是Istio CA健康检查的时间间隔。 interval
是上次更新健康状态文件的最大间隔时间,由prober 判断Istio CA是否健康。 initialDelaySeconds
and periodSeconds
是运行期的初始延迟和探针。
延长 probe-check-interval
将会减少健康检查的开销,但是对于探针察觉不健康状态会产生更大的滞后。为了避免探针由于临时不可用而重启Istio CA,在探针的interval
可以配置比 liveness-probe-interval
大 N
倍。这将允许探针容忍 N-1
连续的健康检查失败。
Cleanup
- 关闭Istio CA的健康检查
kubectl apply -f install/kubernetes/istio-auth.yaml
kubectl delete svc istio-ca -n istio-system
- 移除Istio CA:
kubectl delete -f install/kubernetes/istio-ca-with-health-check.yaml
kubectl delete svc istio-ca -n istio-system