You have two options:
- You could have multiple services, one for each port. As you pointed out, each service will end up with a different IP address
- You could have a single service with multiple ports. In this particular case, you must give all ports a name.
For some Services, you need to expose more than one port. Kubernetes lets you configure multiple port definitions on a Service object. When using multiple ports for a Service, you must give all of your ports names so that these are unambiguous. For example:
How to work with command line?
[ec2-user@ip-172-31-26-152 ~]$ kubectl create service clusterip svc3 --tcp=8080:80 --tcp=8090:80
service/svc3 created
[ec2-user@ip-172-31-26-152 ~]$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d1h
svc1 ClusterIP 10.98.191.0 <none> 8080/TCP 33m
svc2 ClusterIP 10.104.34.223 <none> 8080/TCP,8090/TCP 5m41s
svc3 ClusterIP 10.102.66.226 <none> 8080/TCP,8090/TCP 8s
[ec2-user@ip-172-31-26-152 ~]$ kubectl describe svc svc3
Name: svc3
Namespace: default
Labels: app=svc3
Annotations: <none>
Selector: app=svc3
Type: ClusterIP
IP: 10.102.66.226
Port: 8080-80 8080/TCP
TargetPort: 80/TCP
Endpoints: <none>
Port: 8090-80 8090/TCP
TargetPort: 80/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
Kubernetes – CKA Certification Overview – By DevOpsSchool.com
Kubernetes – CKA Certification | Part 1 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 2 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 3 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 4 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 5 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 6 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 7 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 8 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 9 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 10 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 11 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 12 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 13 out 14 | — By DevOpsSchool
Kubernetes – CKA Certification | Part 14 out 14 | — By DevOpsSchool
Latest posts by Rajesh Kumar (see all)
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024
- Introduction to System Operations (SymOps) - October 30, 2024