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.

댓글

이 블로그의 인기 게시물

Fundamentals of English Grammar #1

To switch to a specific tag in a Git repository

kafka polling vs listen

Create topic on Kafka with partition count, 카프카 토픽 생성하기

Scan an HBase table with a prefix filter

To download a file from MinIO using Spring Boot, 스프링부트 Minio 사용하기

Joining an additional control plane node to an existing Kubernetes cluster

Vespa vs Milvus

max_active_runs of Airflow

urllib3 with proxy settings