V
V
Vadim2021-06-06 17:49:36
Docker
Vadim, 2021-06-06 17:49:36

Why do we use container port in Kubernetes?

Good afternoon,

such a stupid question arose, in the yaml code for pods we can specify the ports directive, for example:

spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 80
          name: nginx-port


The question is why do we actually need this, because the pod still has access to the container's network space? And pod works fine on port 80 and without this directive

, all the best,
Vadim

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2021-06-06
@Viji

in fact, the following yaml just shows that ports: has some informational value, because everything works on the 80th

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 8090
          name: nginx-fake-port

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question