How to expose a Kubernetes service on a specific Nodeport?

后端 未结 6 2078
不思量自难忘°
不思量自难忘° 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:17

    When an existing Dashboard service already exists, remove it.

    kubectl delete service kubernetes-dashboard -n kube-system

    Expose the Dashboard deployment as a NodePort.

    kubectl expose deployment kubernetes-dashboard -n kube-system --type=NodePort

    The above will assign a random port >= 30000. So use the Patch command to assign the port to a known, unused and desired port >= 30000.

    kubectl patch service kubernetes-dashboard --namespace=kube-system --type='json' --patch='[{"op": "replace", "path": "/spec/ports/0/nodePort", "value":30000}]'

    Caution: Never expose your dashboard publicly without authentication.

提交回复
热议问题