How to expose a Kubernetes service on a specific Nodeport?

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

    I had the same problem and the only way I found to do it without modifying the files was:

    k expose --type=NodePort deployment nginx --port 80 --name nginx-ep-patch  --overrides '{ "apiVersion": "v1","spec":{"ports": [{"port":80,"protocol":"TCP","targetPort":80,"nodePort":30080}]}}'
    service/nginx-ep-patch exposed
    

    In this way we path online the configuration and the port 30080 has been exposed:

    $ k describe svc nginx-ep-patch
    Name:                     nginx-ep-patch
    Namespace:                default
    Labels:                   app=nginx
    Annotations:              
    Selector:                 app=nginx
    Type:                     NodePort
    IP:                       10.96.51.148
    Port:                       80/TCP
    TargetPort:               80/TCP
    NodePort:                   30080/TCP
    Endpoints:                10.244.0.6:80
    Session Affinity:         None
    External Traffic Policy:  Cluster
    Events:                   
    

提交回复
热议问题