Skip to content

Instantly share code, notes, and snippets.

@aojea
Created August 27, 2023 19:05
Show Gist options
  • Save aojea/ce7b08fe9e9d57125ccc6a9728a414b6 to your computer and use it in GitHub Desktop.
Save aojea/ce7b08fe9e9d57125ccc6a9728a414b6 to your computer and use it in GitHub Desktop.
Service selector
apiVersion: v1
kind: Pod
metadata:
name: job1
labels:
job-name: "job1"
job-index: "0"
spec:
hostNetwork: true
containers:
- name: job1
image: httpd:2
---
apiVersion: v1
kind: Pod
metadata:
name: job2
labels:
job-name: "job2"
job-index: "0"
spec:
hostNetwork: true
containers:
- name: job2
image: httpd:2
---
apiVersion: v1
kind: Service
metadata:
name: service-good
spec:
selector:
job-name: "job1"
job-index: "0"
ports:
- protocol: TCP
port: 80
targetPort: 9376
---
apiVersion: v1
kind: Service
metadata:
name: service-wrong
spec:
selector:
job-index: "0"
ports:
- protocol: TCP
port: 80
targetPort: 9376
@aojea
Copy link
Author

aojea commented Aug 27, 2023

When applying the manifest, we can observe that the service-wrong gets the endpoints from both pods

 kubectl get endpoints
NAME            ENDPOINTS                           AGE
kubernetes      10.128.0.13:443                     2d22h
service-good    10.128.0.53:9376                    12s
service-wrong   10.128.0.51:9376,10.128.0.53:9376   12s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment