How can you publish a Kubernetes Service without using the type LoadBalancer (on GCP)

后端 未结 3 1085
無奈伤痛
無奈伤痛 2021-02-04 10:43

I would like to avoid using type: \"LoadBalancer\" for a certain Kubernetes Service, but still to be able to publish it on the Internet. I am using Google Cloud Pla

3条回答
  •  死守一世寂寞
    2021-02-04 10:43

    If you don't want to use a LoadBalancer service, other options for exposing your service publicly are:

    Type NodePort

    Create your service with type set to NodePort, and Kubernetes will allocate a port on all of your node VMs on which your service will be exposed (docs). E.g. if you have 2 nodes, w/ public IPs 12.34.56.78 and 23.45.67.89, and Kubernetes assigns your service port 31234, then the service will be available publicly on both 12.34.56.78:31234 & 23.45.67.89:31234

    Specify externalIPs

    If you have the ability to route public IPs to your nodes, you can specify externalIPs in your service to tell Kubernetes "If you see something come in destined for that IP w/ my service port, route it to me." (docs)

    The cluster endpoint won't work for this because that is only the IP of your Kubernetes master. The public IP of another LoadBalancer service won't work because the LoadBalancer is only configured to route the port of that original service. I'd expect the node IP to work, but it may conflict if your service port is a privileged port.

    Use the /proxy/ endpoint

    The Kubernetes API includes a /proxy/ endpoint that allows you to access services on the cluster endpoint IP. E.g. if your cluster endpoint is 1.2.3.4, you could reach my-service in namespace my-ns by accessing https://1.2.3.4/api/v1/proxy/namespaces/my-ns/services/my-service with your cluster credentials. This should really only be used for testing/debugging, as it takes all traffic through your Kubernetes master on the way to the service (extra hops, SPOF, etc.).

提交回复
热议问题