CLB方式:
1.新建一个ipv6的clb,绑定给nginx ingress,可以直接通过svc yaml来实现
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: internet
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ip-version: ipv6
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: 'http:80' #这条很重要
name: nginx-ingress-lb-ipv6
namespace: kube-system
labels:
app: nginx-ingress-lb-ipv6
spec:
ports:
- name: tcp-80-80
port: 80
protocol: TCP
targetPort: 80
- name: tcp-443-443
port: 443
protocol: TCP
targetPort: 443
selector:
app: ingress-nginx
type: LoadBalancer
创建成功以后效果如图
2.修改nginx ingress的configmapkubectl -n kube-system edit cm nginx-configuration
在data模块下添加:
compute-full-forwarded-for: "true"
forwarded-for-header: "X-Forwarded-For"
use-forwarded-headers: "true"
效果如图:
3.测试效果
创建好ingress路由
在本地修改hosts,将预期域名解析到ipv6地址
本地测试
ingress日志:
NLB方式:
1.新建一个NLB实例给nginx ingress controller(注意这个必须要求集群所在vpc及交换机是支持双栈ipv6的,这里测试的ack集群也是ipv6双栈集群,ipv4的ack集群在双栈vpc下能否实现没有测试)
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: internet
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-ip-version: DualStack
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-preserve-client-ip: 'off'
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-proxy-protocol: 'on'
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-zone-maps: >-
cn-chengdu-b:vsw-2vcqjq0tcvvxxxx,cn-chengdu-a:vsw-2vcm16t55w3ycysxxxxx
name: nginx-ingress-nlb-ipv6
namespace: kube-system
spec:
externalTrafficPolicy: Local
ports:
- name: tcp
port: 80
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443
selector:
app: ingress-nginx
sessionAffinity: None
loadBalancerClass: "alibabacloud.com/nlb"
type: LoadBalancer
效果如图:
2.修改nginx ingress的configmap
在data模块下添加:use-proxy-protocol: 'true'
效果如图:
3.测试效果
创建好ingress路由
修改本地hosts,将域名解析到nlb的ipv6地址上
nlb ipv6地址获取如图
修改本地hosts
访问测试: