mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/kube-vip/kube-vip.git
synced 2026-09-20 08:03:47 +08:00
Examples and fixes to annotation interface
Signed-off-by: Dan Finneran <daniel.finneran@gmail.com>
This commit is contained in:
19
example/deployment.yaml
Normal file
19
example/deployment.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:latest
|
||||
ports:
|
||||
- containerPort: 80
|
||||
15
example/service-interface-annotation.yaml
Normal file
15
example/service-interface-annotation.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx-interface-ens192-service
|
||||
annotations:
|
||||
kube-vip.io/serviceInterface: ens192
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 80
|
||||
protocol: TCP
|
||||
13
example/service.yaml
Normal file
13
example/service.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx-service
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 80
|
||||
protocol: TCP
|
||||
@@ -108,7 +108,7 @@ func (cluster *Cluster) vipService(ctxArp, ctxDNS context.Context, c *kubevip.Co
|
||||
|
||||
var ndp *vip.NdpResponder
|
||||
if isIPv6 {
|
||||
ndp, err = vip.NewNDPResponder(c.Interface)
|
||||
ndp, err = vip.NewNDPResponder(cluster.Network[i].Interface())
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create new NDP Responder")
|
||||
}
|
||||
@@ -117,13 +117,13 @@ func (cluster *Cluster) vipService(ctxArp, ctxDNS context.Context, c *kubevip.Co
|
||||
if ndp != nil {
|
||||
defer ndp.Close()
|
||||
}
|
||||
log.Infof("Gratuitous Arp broadcast will repeat every 3 seconds for [%s]", ipString)
|
||||
log.Infof("Gratuitous Arp broadcast will repeat every 3 seconds for [%s/%s]", ipString, cluster.Network[i].Interface())
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done(): // if cancel() execute
|
||||
return
|
||||
default:
|
||||
cluster.ensureIPAndSendGratuitous(c.Interface, ndp)
|
||||
cluster.ensureIPAndSendGratuitous(cluster.Network[i].Interface(), ndp)
|
||||
}
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
@@ -174,10 +174,9 @@ func (cluster *Cluster) StartLoadBalancerService(c *kubevip.Config, bgp *bgp.Ser
|
||||
// ctxArp, cancelArp = context.WithCancel(context.Background())
|
||||
|
||||
ipString := network.IP()
|
||||
|
||||
var ndp *vip.NdpResponder
|
||||
if vip.IsIPv6(ipString) {
|
||||
ndp, err = vip.NewNDPResponder(c.Interface)
|
||||
ndp, err = vip.NewNDPResponder(network.Interface())
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create new NDP Responder")
|
||||
}
|
||||
@@ -186,15 +185,15 @@ func (cluster *Cluster) StartLoadBalancerService(c *kubevip.Config, bgp *bgp.Ser
|
||||
if ndp != nil {
|
||||
defer ndp.Close()
|
||||
}
|
||||
log.Debugf("(svcs) broadcasting ARP update for %s via %s, every %dms", ipString, c.Interface, c.ArpBroadcastRate)
|
||||
log.Debugf("(svcs) broadcasting ARP update for %s via %s, every %dms", ipString, network.Interface(), c.ArpBroadcastRate)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done(): // if cancel() execute
|
||||
log.Debugf("(svcs) ending ARP update for %s via %s, every %dms", ipString, c.Interface, c.ArpBroadcastRate)
|
||||
log.Debugf("(svcs) ending ARP update for %s via %s, every %dms", ipString, network.Interface(), c.ArpBroadcastRate)
|
||||
return
|
||||
default:
|
||||
cluster.ensureIPAndSendGratuitous(c.Interface, ndp)
|
||||
cluster.ensureIPAndSendGratuitous(network.Interface(), ndp)
|
||||
}
|
||||
if c.ArpBroadcastRate < 500 {
|
||||
log.Errorf("arp broadcast rate is [%d], this shouldn't be lower that 300ms (defaulting to 3000)", c.ArpBroadcastRate)
|
||||
|
||||
@@ -43,21 +43,24 @@ func NewInstance(svc *v1.Service, config *kubevip.Config) (*Instance, error) {
|
||||
instanceUID := string(svc.UID)
|
||||
|
||||
// Detect if we're using a specific interface for services
|
||||
var serviceInterface string
|
||||
config.ServicesInterface = svc.Annotations[serviceInterface] // If the service has a specific interface defined, then use it
|
||||
if config.ServicesInterface != "" {
|
||||
serviceInterface = config.ServicesInterface
|
||||
} else {
|
||||
serviceInterface = config.Interface
|
||||
}
|
||||
var svcInterface string
|
||||
svcInterface = svc.Annotations[serviceInterface] // If the service has a specific interface defined, then use it
|
||||
|
||||
// If it is still blank then use the
|
||||
if svcInterface == "" {
|
||||
if config.ServicesInterface != "" {
|
||||
svcInterface = config.ServicesInterface
|
||||
} else {
|
||||
svcInterface = config.Interface
|
||||
}
|
||||
}
|
||||
var newVips []*kubevip.Config
|
||||
|
||||
for _, address := range instanceAddresses {
|
||||
// Generate new Virtual IP configuration
|
||||
newVips = append(newVips, &kubevip.Config{
|
||||
VIP: address,
|
||||
Interface: serviceInterface,
|
||||
Interface: svcInterface,
|
||||
SingleNode: true,
|
||||
EnableARP: config.EnableARP,
|
||||
EnableBGP: config.EnableBGP,
|
||||
@@ -138,6 +141,8 @@ func NewInstance(svc *v1.Service, config *kubevip.Config) (*Instance, error) {
|
||||
}
|
||||
|
||||
instance.clusters = append(instance.clusters, c)
|
||||
log.Infof("(svcs) adding VIP [%s] via %s for [%s/%s]", vipConfig.VIP, vipConfig.Interface, svc.Namespace, svc.Name)
|
||||
|
||||
}
|
||||
|
||||
return instance, nil
|
||||
|
||||
@@ -106,8 +106,6 @@ func (sm *Manager) addService(svc *v1.Service) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("(svcs) adding VIP [%s] for [%s/%s]", newService.VIPs, newService.serviceSnapshot.Namespace, newService.serviceSnapshot.Name)
|
||||
|
||||
for x := range newService.vipConfigs {
|
||||
newService.clusters[x].StartLoadBalancerService(newService.vipConfigs[x], sm.bgpServer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user