K8S中将一个Deployment暴露出一个指定的外部端口,生成yaml

  • K8S中将一个Deployment暴露出一个指定的外部端口

  • 如何固定NodePort端口

    • 如何固定NodePort端口 - 知乎
  • kubectl expose deployment quickstart-kb --name=kibana-svc --port=5601 --target-port=5601 --type=NodePort --dry-run=client -o yaml > quickstart-kb-svc.yaml


[root@k8s-master01 ~]# vi quickstart-kb-svc.yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    common.k8s.elastic.co/template-hash: "3483830521"
    common.k8s.elastic.co/type: kibana
    kibana.k8s.elastic.co/name: quickstart
  name: kibana-svc
spec:
  ports:
  - port: 5601
    protocol: TCP
    targetPort: 5601
    nodePort: 30123    # 添加固定端口
  selector:
    common.k8s.elastic.co/type: kibana
    kibana.k8s.elastic.co/name: quickstart
  type: NodePort
status:
  loadBalancer: {}


kubectl apply -f quickstart-kb-svc.yaml

[root@k8s-master01 ~]# kubectl get svc
NAME                          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kibana-svc                    NodePort    10.102.46.24             5601:30123/TCP   2s


你可能感兴趣的:(kubernetes,容器,云原生)