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.

댓글

이 블로그의 인기 게시물

Install and run an FTP server using Docker

Using the MinIO API via curl

PYTHONPATH, Python 모듈 환경설정

Elasticsearch Ingest API

오늘의 문장2

How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

Fundamentals of English Grammar #1

To switch to a specific tag in a Git repository

You can use Sublime Text from the command line by utilizing the subl command

티베트-버마어파 와 한어파(중국어파)의 어순 비교