一、配置全局LoadBalancer类型的SVC的IPPool
apiVersion: "cilium.io/v2alpha1"
kind: CiliumLoadBalancerIPPool
metadata:
name: "pool"
spec:
blocks:
- cidr: "20.0.10.0/24"
二、配置基于label的LoadBalancer类型的SVC的IPPool
# Expression selector
apiVersion: "cilium.io/v2alpha1"
kind: CiliumLoadBalancerIPPool
metadata:
name: "pool-primary"
spec:
blocks:
- cidr: "60.0.10.0/24"
serviceSelector:
matchExpressions:
- {key: color, operator: In, values: [yellow, red, blue]}
# # Second pool, label selector
apiVersion: "cilium.io/v2alpha1"
kind: CiliumLoadBalancerIPPool
metadata:
name: "pool-green"
spec:
blocks:
- cidr: "40.0.10.0/24"
serviceSelector:
matchLabels:
color: green
三、 通过注释获取特定ip的方式(k8s 1.24弃用)并且同时存在CiliumLoadBalancerIPPool
apiVersion: v1
kind: Service
metadata:
name: service-yellow
namespace: tenant-c
labels:
color: yellow
annotations:
"io.cilium/lb-ipam-ips": "30.0.10.100,40.0.10.100,50.0.10.100,60.0.10.100"
spec:
type: LoadBalancer
ports:
- port: 1234
root@server:~# yq pool-yellow.yaml
# Namespace selector
apiVersion: "cilium.io/v2alpha1"
kind: CiliumLoadBalancerIPPool
metadata:
name: "pool-yellow"
spec:
blocks:
- cidr: "50.0.10.0/24"
serviceSelector:
matchLabels:
"io.kubernetes.service.namespace": "tenant-c"
root@server:~# kubectl get svc/service-yellow -n tenant-c
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service-yellow LoadBalancer 10.96.76.161 50.0.10.100,60.0.10.100 1234:32555/TCP 11s
*会同时获取到两个地址
Note that the Service was allocated two of the requested IP addresses:
50.0.10.100
because it matches the namespace (tenant-c
).60.0.10.100
because it matches the primary colours labels.
第一个地址匹配SVC。
第二个地址匹配CiliumLoadBalancerIPPool。