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

Sparse encoder

max_active_runs of Airflow

how to delete all issues on project in sentry, 센트리 이슈 삭제하기

Nginx Openssl 설정

difference between truncate and truncate_preserve in hbase

To monitor logs for a Kubernetes CronJob

Sort the distinct values by their count in descending order using the DataFrame API

Chromium 개발 환경 세팅, 크로미움 개발 준비하기

Bash script samples