Kubernetes Headless Service multi-interface Pod

7/8/2020

I can't add a comment to this question https://stackoverflow.com/questions/57254091/kubernetes-headless-service-resolves-to-specific-interface-of-a-multi-interface/62798573#62798573

I have the same requirment, but the post does not say if the issue was resolved, so reposting.

Here is the yaml:

apiVersion: v1
kind: Service
metadata:
  name: ovnkube-db
  namespace: ovn-kubernetes
spec:
  ports:
  - name: north
    port: 6641
    protocol: TCP
    targetPort: 6641
  - name: south
    port: 6642
    protocol: TCP
    targetPort: 6642
  sessionAffinity: None
  clusterIP: None
  type: ClusterIP

---

apiVersion: v1
kind: Endpoints
metadata:
  name: ovnkube-db
subsets:
  - addresses:
      - ip: 253.255.0.33
      - ip: 253.255.0.34
      - ip: 253.255.0.35
    ports:
    - name: north
      port: 6641
    - name: south
      port: 6642
---

apiVersion: policy/v1beta1
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: ovndb-raft-pdb
  namespace: ovn-kubernetes

etc...

Based on the post I referenced and the kubernetes docs, I thought adding the Endpoints section would solve my problem, but no:

kubectl describe services --namespace=ovn-kubernetes
Name:              ovnkube-db
Namespace:         ovn-kubernetes
Labels:            <none>
Annotations:       kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"ovnkube-db","namespace":"ovn-kubernetes"},"spec":{"clusterIP":"None","ports":[...
Selector:          <none>
Type:              ClusterIP
IP:                None
Port:              north  6641/TCP
TargetPort:        6641/TCP
Endpoints:         10.68.48.204:6641,10.68.48.205:6641,10.68.48.206:6641
Port:              south  6642/TCP
TargetPort:        6642/TCP
Endpoints:         10.68.48.204:6642,10.68.48.205:6642,10.68.48.206:6642
Session Affinity:  None
Events:            <none>

My IPs are:

ip a | grep "inet "
    inet 127.0.0.1/8 scope host lo
    inet 10.68.48.204/22 brd 10.68.51.255 scope global eno1
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
    inet 253.255.0.33/16 brd 253.255.255.255 scope global bond0.3900
    inet 253.255.0.32/32 scope global bond0.3900
    inet 10.244.0.0/32 scope global flannel.1
    inet 10.244.0.1/24 brd 10.244.0.255 scope global cni0
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0

My kube-apiserver is on 253.255:

kubectl config view | grep server
    server: https://253.255.0.33:6443
    enter code here
-- Bren
kubernetes

2 Answers

7/8/2020

Yeup, it was the namespace, so I can confirm, this works :)

-- Bren
Source: StackOverflow

7/9/2020

The problem was that namespace was missing. This fixes it.

apiVersion: v1
kind: Endpoints
metadata:
  name: ovnkube-db
  namespace: ovn-kubernetes
subsets:
  - addresses:
      - ip: 253.255.0.33
      - ip: 253.255.0.34
      - ip: 253.255.0.35
    ports:
    - name: north
      port: 6641
    - name: south
      port: 6642
-- Bren
Source: StackOverflow