0

I was playing with k8s deployment with change of port for service,container and ingress.I am curious to know how the deployment is working.

my scenario : To deploy one rest service application hosting 2 endpoints.

Case 1:

containerPort: 8081 - # port for container

port: 8081 #port of the service targetPort: 8081

Host1 port : 8081 #port of the ingress Host2 port :8081

Result : deployed successfully using bamboo pipeline as expected.

Case 2: containerPort: 8080 - # port for container

port: 8080 #port of the service targetPort: 8081

Host1 port : 8081 #port of the ingress Host2 port :8081 Result : Deployment is getting failed in bamboo but health check and all end points are working fine.

Case 3:

containerPort: 8080 - # port for container

port: 8080 #port of the service targetPort: 808

Host1 port : 8080 #port of the ingress Host2 port :8080

Result : deployment unsuccessful in bamboo which is also expected because another host is running also in 8080 in the same cluster.

I am really not sure why Case 2 is failing. Can someone help me?

learner
  • 223
  • 3
  • 19
  • Hi there, can you please format the question with some `code block` as for now, it's not really easy to read. Also can you provide some more info and background, please ? Remember that we are not working in your current project so we don't know the current situation. – Marc ABOUCHACRA Nov 26 '19 at 15:06

1 Answers1

0

Case 2:

containerPort: 8080 - # port for container

port: 8080 #port of the service targetPort: 8081

Host1 port : 8081 #port of the ingress Host2 port :8081

Result : Deployment is getting failed in bamboo but health check and all end points are working fine.

I am really not sure why Case 2 is failing. Can someone help me?

You cannot expect it to be working if you set targetPort in your Service to 8081 and the port that your container exposes (port that your pod is listening on) is 8080. These two values must much. Please refer to this article in official k8s documentation.

mario
  • 9,858
  • 1
  • 26
  • 42
  • Sorry but why these two values should match? – learner Nov 27 '19 at 10:46
  • If you want to expose some set of `Pods` as a `Service`, apart from setting a `port:` that it will be listening on, you should tell it which ports actual `Pods` are listening on (ports defined in `container:` specification as `containerPort:` ). This is the function of `targetPort:`. You use it so the `Service` knows to which port on the container it should map its `port:` it listens on. If you don't have any `Pods` exposing port `8081` how can you map anything to that port ? – mario Nov 27 '19 at 11:47