Allow Mapping Services Feature to Work With Headless Services
Is your feature request related to a problem?
If I set:
mapServices:
fromVirtual:
- from: mongo/mongodb-headless
to: mongodb-headless
Then I try to connect using the pod names e.g. mongodb-headless-0.mongodb-headless it fails and seems to not map the replicas to the service properly.
Which solution do you suggest?
I suggest to allow mapservices feature to work with headless services.
Which alternative solutions exist?
No response
Additional context
No response
Hi @sharkymcdongles , thanks for creating this issue. From my initial skim through the code, what seems to be the case here is the service is created but the service.spec.type is not taken into account – hence the headless part not working as expected. Is it what you're seeing in your case as well?
Hi @sharkymcdongles , thanks for creating this issue. From my initial skim through the code, what seems to be the case here is the service is created but the
service.spec.typeis not taken into account – hence theheadlesspart not working as expected. Is it what you're seeing in your case as well?
Yes, this seems to be the case. Also, a headless service is created if ClusterIP is set to None. We were able to create a workaround by customising the CoreDNS settings but in general it would be cleaner if the map services feature worked.
@ishankhare07 your change works as expected when I am mapping from vcluster to host, but if I try and map from host to vcluster then it doesn't seem to work. I checked the code, and it seems like it uses the same method even if it is to host to virtual or vice versa. Any idea?
Here is what I see in the vcluster:
Name: mongodb-headless
Namespace: default
Labels: vcluster.loft.sh/controlled-by=vcluster
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP Family Policy: RequireDualStack
IP Families: IPv4,IPv6
IP: None
IPs: None
Port: mongodb 27017/TCP
TargetPort: mongodb/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
@sharkymcdongles alright, I can see the selectors field to be empty first of all along with annotations. Can you post a detailed yaml of the service objects for both the fromHost and fromVirtual cases for comparision?
Our use case would be to link a DB e.g Mongo from vcluster A to app in vcluster B using headless svc-s.
@ishankhare07 Here are more details. First, using your change allowed headless services to work from vcluster to host cluster and works as expected.
headless service within the vcluster:
Name: mongodb-headless
Namespace: default
Labels: app.kubernetes.io/component=mongodb
app.kubernetes.io/instance=mongodb
app.kubernetes.io/managed-by=Helm
app.kubernetes.io/name=mongodb
helm.sh/chart=mongodb-13.6.6
Annotations: meta.helm.sh/release-name: mongodb
meta.helm.sh/release-namespace: default
Selector: app.kubernetes.io/component=mongodb,app.kubernetes.io/instance=mongodb,app.kubernetes.io/name=mongodb
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: None
IPs: None
Port: mongodb 27017/TCP
TargetPort: mongodb/TCP
Endpoints: 10.114.11.25:27017,10.114.3.8:27017,10.114.7.9:27017
Session Affinity: None
Events: <none>
Headless service mapped from vcluster to host cluster:
Name: infrastructure-mongodb-headless
Namespace: loft-default-v-my-vcluster
Labels: vcluster.loft.sh/controlled-by=vcluster
Annotations: cloud.google.com/neg: {"ingress":true}
Selector: vcluster.loft.sh/label-my-vcluster-x-71dafa318e=mongodb,vcluster.loft.sh/label-my-vcluster-x-9039c53507=mongodb,vcluster.loft.sh/label-my-vcluster-x-b71e98ce1a=mongodb,vcluster.loft.sh/managed-by=my-vcluster,vcluster.loft.sh/namespace=default
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: None
IPs: None
Port: mongodb 27017/TCP
TargetPort: mongodb/TCP
Endpoints: 10.114.11.25:27017,10.114.3.8:27017,10.114.7.9:27017
Session Affinity: None
Events: <none>
Helm values for this vcluster:
globalAnnotations:
iam.gke.io/gcp-service-account: [email protected]
hostpathMapper:
enabled: true
mapServices:
fromVirtual:
- from: default/mongodb-headless
to: infrastructure-mongodb-headless
nodeSelector:
persistent: "true"
serviceCIDR: 10.115.0.0/16
storage:
className: fast
persistence: true
size: 256Gi
sync:
ingresses:
enabled: false
nodes:
enabled: true
syncAllNodes: true
persistentvolumeclaims:
enabled: true
persistentvolumes:
enabled: true
priorityclasses:
enabled: true
storageclasses:
enabled: true
syncer:
image: harborrepo.com/library/vcluster:test
resources:
limits:
cpu: 4000m
memory: 4Gi
requests:
cpu: 2000m
memory: 2Gi
vcluster:
image: rancher/k3s:v1.24.7-k3s1
resources:
limits:
memory: 8Gi
requests:
cpu: 1000m
memory: 2Gi
helm values for mapping from host to vcluster
hostpathMapper:
enabled: true
globalAnnotations:
iam.gke.io/gcp-service-account: [email protected]
nodeSelector:
persistent: "true"
mapServices:
fromHost:
- from: loft-default-v-my-vcluster/infrastructure-mongodb-headless
to: default/mongodb-headless
vcluster:
resources:
limits:
memory: 8Gi
requests:
cpu: 1000m
memory: 2Gi
storage:
persistence: true
size: 256Gi
className: fast
syncer:
resources:
limits:
cpu: 4000m
memory: 4Gi
requests:
cpu: 2000m
memory: 2Gi
sync:
nodes:
enabled: true
syncAllNodes: true
ingresses:
enabled: false
persistentvolumes:
enabled: true
persistentvolumeclaims:
enabled: true
priorityclasses:
enabled: true
storageclasses:
enabled: true
service in vcluster:
Name: mongodb-headless
Namespace: default
Labels: vcluster.loft.sh/controlled-by=vcluster
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP Family Policy: RequireDualStack
IP Families: IPv4,IPv6
IP: None
IPs: None
Port: mongodb 27017/TCP
TargetPort: mongodb/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
service on host: I don't see one on the host for this at all
I also tried another with the test image using your change:
service in vcluster:
Name: mongodb-headless
Namespace: default
Labels: vcluster.loft.sh/controlled-by=vcluster
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP Family Policy: RequireDualStack
IP Families: IPv4,IPv6
IP: None
IPs: None
Port: mongodb 27017/TCP
TargetPort: mongodb/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
No service on host. Here are the values:
globalAnnotations:
iam.gke.io/gcp-service-account: [email protected]
hostpathMapper:
enabled: true
mapServices:
fromHost:
- from: loft-default-v-my-vcluster/infrastructure-mongodb-headless
to: default/mongodb-headless
nodeSelector:
persistent: "true"
serviceCIDR: 10.115.0.0/16
storage:
className: fast
persistence: true
size: 256Gi
sync:
ingresses:
enabled: false
nodes:
enabled: true
syncAllNodes: true
persistentvolumeclaims:
enabled: true
persistentvolumes:
enabled: true
priorityclasses:
enabled: true
storageclasses:
enabled: true
syncer:
image: harborrepo.com/library/vcluster:test
resources:
limits:
cpu: 4000m
memory: 4Gi
requests:
cpu: 2000m
memory: 2Gi
vcluster:
image: rancher/k3s:v1.24.7-k3s1
resources:
limits:
memory: 8Gi
requests:
cpu: 1000m
memory: 2Gi
@sharkymcdongles @SCLogo If I understand correctly you already have the virtual -> host headless service mapped correctly. Meaning you have a headless service on host loft-default-v-my-vcluster/infrastructure-mongodb-headless which you can access from your vcluster-B application as <service name>.<namespace name>.svc.cluster.local – which in this case would become like infrastructure-mongodb-headless.loft-default-v-my-vcluster or infrastructure-mongodb-headless.loft-default-v-my-vcluster.svc.cluster.local
Also about your second mapping, you're trying to map loft-default-v-my-vcluster/infrastructure-mongodb-headless -> default/mongodb-headless
- I think you don't need this for the reason I pointed above
- If you're looking for the resulting mapped service, you won't find it on host, you'll find it on the host's
defaultnamespace, it will be indefaultnamespace in vcluster but in the<vcluster-B>namespace in the host (i.e. the namespace the second vcluster is created in)
Maybe this would help you better - https://stackoverflow.com/questions/37221483/service-located-in-another-namespace
@sharkymcdongles @SCLogo If I understand correctly you already have the virtual -> host headless service mapped correctly. Meaning you have a headless service on host
loft-default-v-my-vcluster/infrastructure-mongodb-headlesswhich you can access from yourvcluster-Bapplication as<service name>.<namespace name>.svc.cluster.local– which in this case would become likeinfrastructure-mongodb-headless.loft-default-v-my-vclusterorinfrastructure-mongodb-headless.loft-default-v-my-vcluster.svc.cluster.localAlso about your second mapping, you're trying to map
loft-default-v-my-vcluster/infrastructure-mongodb-headless->default/mongodb-headless
- I think you don't need this for the reason I pointed above
- If you're looking for the resulting mapped service, you won't find it on host, you'll find it on the host's
defaultnamespace, it will be indefaultnamespace in vcluster but in the<vcluster-B>namespace in the host (i.e. the namespace the second vcluster is created in)Maybe this would help you better - https://stackoverflow.com/questions/37221483/service-located-in-another-namespace
I think you misunderstand what I did so I will explain clearer my bad.
So first I mapped a headless service from a vcluster to the host cluster. When I did this it came over as a headless service and worked as expected.
I then created a new vcluster. This new vcluster was using the image built from master that had your change in it. For this vcluster I then tried to map the headless service from the host cluster that was mapped from the original vcluster. So to be clear:
vcluster -> headless service -> host -> headless service -> vcluster2
This is what is in the vcluster when I do the above flow:
Name: mongodb-headless
Namespace: default
Labels: vcluster.loft.sh/controlled-by=vcluster
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP Family Policy: RequireDualStack
IP Families: IPv4,IPv6
IP: None
IPs: None
Port: mongodb 27017/TCP
TargetPort: mongodb/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
The headless service that is mapped from host into vcluster2 is not a headless service or works as one would expect as you can see above.
I also tried this flow as well with just a headless service on host into a vcluster:
host -> headless service -> vcluster
This one also doesn't seem to work as expected.
@sharkymcdongles and @ishankhare07 I am also able to reproduce the problem. I have a Kafka broker deployed as a stateful set in my host cluster and I would like it to be shared across all my vclusters. The headless service in the host cluster is synced to vcluster, although the service selectors are not synchronized into the vcluster. I have been trying to get more information but failing.