aliyun-k8s_svc绑定elb

阅读量: zyh 2021-03-08 17:46:16
Categories: > Tags:

svc阿里云特殊注解

    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec: slb.s1.small      # 申请的elb资源类型
    service.beta.kubernetes.io/alicloud-loadbalancer-address-type: intranet       # 申请的elb内外网类型(如果不显式指定,就是外网)
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-additional-resource-tags: "A=B" # 附加的阿里云资源标签
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: "lb-8vbblzrcxxxxxxxx"  # 绑定已有的ELB-ID
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners: "true" # 是否将svc声明的spec规则强制覆盖ELB已有规则

例子

通过绑定已有的elb,避免因elb变更,导致对外服务的ip发生变动。

apiVersion: v1
kind: Service
metadata:
  name: svc-nginx-b
  namespace: b
  annotations:
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-additional-resource-tags: "project=b"
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: "lb-8vbblzrcxxxxxxxx"
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners: "true"
spec:
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
    - name: https
      protocol: TCP
      port: 443
      targetPort: 443
  selector:
    app: nginx-b
  sessionAffinity: None
  type: LoadBalancer
---
apiVersion: v1
kind: Service
metadata:
  name: svc-fpm-b
  namespace: b
spec:
  ports:
    - name: tcp
      protocol: TCP
      port: 9000
      targetPort: 9000
  selector:
    app: fpm-b
  sessionAffinity: None
  type: ClusterIP