Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Container port pods vs container port service

Tags:

kubernetes

I would like to understand the mapping between the service port and pod container port.

Do I need to define the container port as part of my pod and also as part of my service? Or it's ok just to expose it as part of the service?

like image 638
Peter Avatar asked Apr 18 '19 07:04

Peter


People also ask

What is the difference between a pod and a service?

Kubernetes Service vs Deployment A deployment is responsible for keeping a set of pods running. A service is responsible for enabling network access to a set of pods. We could use a deployment without a service to keep a set of identical pods running in the Kubernetes cluster.

What is POD container port?

“containerPort” defines the port on which app can be reached out inside the container. once your container is spun up and the pod is running. You may need to expose the POD as a service to the external world sometimes. Kubernetes service comes into the picture here.

What is the difference between pods and containers?

Pod is just a co-located group of container and an Kubernetes object. Instead of deploying them separate you can do deploy a pod of containers . Best practices is that you should not actually run multiple processes via single container and here is the place where pod idea comes to a place.

Is a Kubernetes pod the same as a container?

Overview. A Kubernetes pod is a collection of one or more Linux® containers, and is the smallest unit of a Kubernetes application. Any given pod can be composed of multiple, tightly coupled containers (an advanced use case) or just a single container (a more common use case).


1 Answers

containerPort as part of the pod definition is only informational purposes. Ultimately if you want to expose this as a service within the cluster or node then you have to create a service.

To answer your question, yes it is enough if you just expose it as part of the Kubernetes service. It is a good practice to mention as part of the pod definition so that if someone looks at the definition can understand the port where your container service is running.

This is very well explained here

Official kubernetes reference documentation

like image 179
Lokesh Avatar answered Sep 23 '22 01:09

Lokesh