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

2023-12-29 06:13:20
  • K8S中将一个Deployment暴露出一个指定的外部端口

  • 如何固定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     <none>        5601:30123/TCP   2s


文章来源:https://blog.csdn.net/alksjdfp32r/article/details/135270524
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。