How to expose a Kubernetes service on a specific Nodeport?

后端 未结 6 2086
不思量自难忘°
不思量自难忘° 2021-02-07 00:04

I have create a pod with the below yaml definition.

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: m         


        
6条回答
  •  广开言路
    2021-02-07 00:28

    we can expose Kubernetes service on specific node port.

    Port value must be between 30000-32767.

    We can expose service to specific port of below service types:

    1. NodePort

    2. LoadBalancer

    Find the sample myservice.yaml file below:

    apiVersion: v1
    kind: Service
    metadata:
      name: app1
    spec:
      type: NodePort/LoadBalancer
      ports:
      - name: "80"
        port: 80
        nodePort: 32062
        targetPort: 80
      selector:
        appone: app1
        app: test
    

    Note: In above service yaml file we can specify service type either NodePort or Loadbalancer.

提交回复
热议问题