原创-阿里云上SLB暴露K8S服务-四层协议/七层协议

注意:在阿里的k8s中使用SLB,当服务(pod)发生漂移后,slb后端也会动态修改,此时会有瞬间的5xx错误,同时注意会覆盖原先手动配置的配置。因此给K8S提供SLB时最好使用全新的SLB。

---四层协议yaml文件---

apiVersion: v1

kind: Service

metadata:

 annotations:

   service.beta.kubernetes.io/alicloud-loadbalancer-id: "你的SLB实例ID"

   service.beta.kubernetes.io/alicloud-loadbalancer-address-type: intranet

   service.beta.kubernetes.io/alicloud-loadbalancer-force-override-listeners: "true"

 name: xlvip-api-grpc-slb

 namespace: xlvip

spec:

 externalTrafficPolicy: Local

 ports:

 - name: grpc

   port: 50051

   protocol: TCP

   targetPort: 50051

 selector:

   xlvip-app: xlvip-api-grpc

 sessionAffinity: None

 type: LoadBalancer

---七层协议yaml文件---

apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alicloud-loadbalancer-cert-id: 你的域名证书id
service.beta.kubernetes.io/alicloud-loadbalancer-force-override-listeners: "true"
service.beta.kubernetes.io/alicloud-loadbalancer-health-check-flag: "on"
service.beta.kubernetes.io/alicloud-loadbalancer-health-check-interval: "10"
service.beta.kubernetes.io/alicloud-loadbalancer-health-check-timeout: "5"
service.beta.kubernetes.io/alicloud-loadbalancer-health-check-type: http
service.beta.kubernetes.io/alicloud-loadbalancer-health-check-uri: /healthz
service.beta.kubernetes.io/alicloud-loadbalancer-healthy-threshold: "2"
service.beta.kubernetes.io/alicloud-loadbalancer-id: 你的SLB实例ID
service.beta.kubernetes.io/alicloud-loadbalancer-protocol-port: https:443,http:80
service.beta.kubernetes.io/alicloud-loadbalancer-unhealthy-threshold: "3"
labels:
app: nginx-ingress-lb
name: nginx-ingress-xshare-lb
namespace: xlsdk
spec:
externalTrafficPolicy: Local
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 80
selector:
app: ingress-nginx
sessionAffinity: None
type: LoadBalancer

上一篇:【报告分享】2020-2021中国企业AI成熟度研究报告-IDC&第四范式(附下载)


下一篇:阿里云 SLB(Server Load Balance)