Kubernetes Views 3

Exposing containers on Kubernetes

Exposing containers on Kubernetes image 1

What does exposing a container mean?

Containers deployed on Kubernetes run inside the Kubernetes cluster by default.
So if you want to reach them from the outside, you have to create a Service.
On Kubernetes, creating a Service is also described as exposing, and it is like mapping an outside port to a port on the inner container.

Exposing containers on Kubernetes image 2


# Exposing — YAML

To expose something on Kubernetes you can deploy a Service or expose it directly from the CLI.
When you deploy a Service, you can write a YAML file and apply it.

YAML
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app.kubernetes.io/name: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

The YAML above means port 80 is exposed externally and is mapped to port 9376 on the container.

You can also set type, external-IP, and so on when you deploy it.

Exposing with expose

XML
kubectl expose -n <namespace>  <kind> <pod> -name [서비스네임] --port --target-port

You can also expose it from the CLI as shown above.

Reactions

Comments 0

A nickname and a password are required. The same password edits or deletes the comment later. Comments appear after a review.

Comments appear after a review. The password is used again to edit or delete.