In Kubernetes (k8s), Expose pod as NodePort

In Kubernetes (k8s), a Pod is the smallest deployable unit that represents a single instance of a running process in a cluster. A NodePort is a type of Kubernetes service that exposes a port on each node of the cluster and forwards traffic to a service.

When you create a Kubernetes service with type NodePort, Kubernetes automatically assigns a random port between 30000 and 32767 to the service. You can also specify a particular port number within that range to be used.

To create a service with type NodePort, you can use the kubectl expose command with the --type=NodePort flag, like this:

kubectl expose pod my-pod --type=NodePort --name=my-service

This command creates a service named my-service that exposes the pod named my-pod on a randomly assigned port.

Alternatively, you can create a service manifest file with the following content:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8080
    nodePort: 30080
  selector:
    app: my-app

In this example, the service exposes port 80 on each node in the cluster, and forwards traffic to port 8080 on pods with the label app=my-app. The nodePort field specifies that the service should be exposed on port 30080 on each node.

Once the service is created, you can access it using the IP address of any node in the cluster and the nodePort you specified (or the random port assigned by Kubernetes if you didn't specify one). For example, if the IP address of one of your nodes is 10.0.0.1 and the nodePort is 30080, you could access the service using the URL http://10.0.0.1:30080.

댓글

이 블로그의 인기 게시물

Using the MinIO API via curl

vsftpd default directory

Using venv in Python

Offset out of range error in Kafka, 카프카 트러블슈팅

리눅스 (cron - 주기적 작업실행 데몬)

[Ubuntu] *.deb 파일 설치 방법

Sparse encoder

Retrieving Open Graph (OG) tags from an HTML document in Java