I'm using a ReplicaSet to manage my pods and I try to expose these pods with a service. The Pods created by a ReplicaSet have randomized names.
NAME READY STATUS RESTARTS AGE
master 2/2 Running 0 20m
worker-4szkz 2/2 Running 0 21m
worker-hwnzt 2/2 Running 0 21m
I try to expose these Pods with a Service, since some policies restrict me to use hostNetwork=true
. I'm able to expose them by creating a NodePort
service for each Pod with kubectl expose pod worker-xxxxx --type=NodePort
.
This is clearly not a flexible way. I wonder how to create a Service (LoadBalancer type maybe?) to access to all the replicas dynamically in my ReplicaSet. If that comes with a Deployment that would be perfect too.
Thanks for any help and advice!
Edit:
I put a label on my ReplicaSet and a NodePort type Service called worker
selecting that label. But I'm not able to ping worker
in any of my pods. What's the correct way of doing this?
Below is how the kubectl describe service worker
gives. As the Endpoints
show the pods are picked up.
Name: worker
Namespace: default
Annotations: <none>
Selector: tag=worker
Type: NodePort
IP: 10.106.45.174
Port: port1 29999/TCP
TargetPort: 29999/TCP
NodePort: port1 31934/TCP
Endpoints: 10.32.0.3:29999,10.40.0.2:29999
Port: port2 29996/TCP
TargetPort: 29996/TCP
NodePort: port2 31881/TCP
Endpoints: 10.32.0.3:29996,10.40.0.2:29996
Port: port3 30001/TCP
TargetPort: 30001/TCP
NodePort: port3 31877/TCP
Endpoints: 10.32.0.3:30001,10.40.0.2:30001
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
app: worker
, and creating a service with selectorapp: worker
? That service should act like a load balancer in front of all the pods with that label. - Burak SerdarNodePort
Service with the matching selectors and the Service is showing the worker Pods inEndpoints
. But I'm not able toping worker
in master (worker
is the Service name). Do you know am I doing wrong? Thank you! - OrlandoLkubectl get pods
output. Themaster
is a pod in k8s cluster so I expect it to be able to talk to the worker pods through that service. I added an edit of the service port forwarding. Am I not ping-ing the correct ports? Thanks! - OrlandoL