Expose port 80 on Digital Ocean's managed Kubernetes without a load balancer

后端 未结 2 1812
梦毁少年i
梦毁少年i 2020-12-28 19:11

I would like to expose my Kubernetes Managed Digital Ocean (single node) cluster\'s service on port 80 without the use of Digital Ocean\'s load balancer. Is this possible? H

2条回答
  •  天命终不由人
    2020-12-28 19:51

    A NodePort Service can do what you want. Something like this:

    kind: Service
    apiVersion: v1
    metadata:
      name: my-service
    spec:
      type: NodePort
      selector:
        app: MyApp
      ports:
      - protocol: TCP
        nodePort: 80
        targetPort: 80
    

    This will redirect incoming traffic from port 80 of the node to port 80 of your pod. Publish the node IP in DNS and you're set.

    In general exposing a service to the outside world like this is a very, very bad idea, because the single node passing through all traffic to the service is both going to receive unbalanced load and be a single point of failure. That consideration doesn't apply to a single-node cluster, though, so with the caveat that LoadBalancer and Ingress are the fault-tolerant ways to do what you're looking for, NodePort is best for this extremely specific case.

提交回复
热议问题