Hi Team,
Kindly help me in understanding this question. Question mentions that container port 80 so this should be Targetport. Is my understanding correct ?
Do we need to change target port to “80” or both port and target port to 80 . Issue resolved by changing both to 80. Kindly assist. Thanks!
Solve this question on: ssh cluster1-controlplane
The purple-app-cka27-trb pod is an nginx based app on the container port 80. This app is exposed within the cluster using a ClusterIP type service called purple-svc-cka27-trb.
There is another pod called purple-curl-cka27-trb which continuously monitors the status of the app running within purple-app-cka27-trb pod by accessing the purple-svc-cka27-trb service using curl.
Recently, we started seeing some errors in the logs of the purple-curl-cka27-trb pod.
Dig into the logs to identify the issue and resolve it.
Are the issues fixed?
hi @sakshibag80
Port vs TargetPort in Kubernetes Services
port and targetPort are two key fields in a Kubernetes Service definition that control how traffic is routed from the Service to the Pods:
port
- This is the port on which the Service itself is exposed inside the cluster.
- Other pods and services within the cluster use this port to communicate with the Service.
- Example: If
port: 80
, the Service is accessible at port 80 within the cluster.
targetPort
- This is the port on the Pod’s container that receives the traffic forwarded by the Service.
- It tells Kubernetes which port on the selected pods should receive the incoming traffic.
- Example: If
targetPort: 8080
, the Service forwards incoming traffic to port 8080 on the Pod’s container.
I guess to answer your question plainly, you need to check both the port (port that the service is exposed on) and targetport (port the container in the pod is exposed on).
for this question, the app was listening on port 80 (according to the question). Also if you check in the purple-curl pod:
cluster1-controlplane ~ ➜ k get pod purple-curl-cka27-trb -o yaml
you’ll see:
spec:
containers:
- command:
- /bin/sh
- -c
- while true; do timeout 3 curl -s http://purple-svc-cka27-trb || echo Not able
to connect to the nginx app on http://purple-svc-cka27-trb; sleep 3; done
This means that the purple-curl app is also trying to use http connection to reach the service. if the port is not explicitly specified, it defaults to port 80. So your service has to be listening (or exposed) on port 80 as well.
I hope this makes sense. Cheers fam.
Hi @sakshibag80
If your query is based on this:
The purple-app-cka27-trb pod is an nginx based app on the container port 80.
It mainly mentions that the named Pod has the application listening on port 80 inside the container.
It’s defined in the Pod’s containerSpec:
spec:
containers:
- image: nginx
name: nginx-container
ports:
- containerPort: 80
You can try viewing the logs of the Pods and see what’s happening