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? How would I do this?
This is essentially a hobby project (I am beginning with Kubernetes) and just want to keep the cost very low.
In other words, Kubernetes services are themselves the crudest form of load balancing traffic. In Kubernetes the most basic type of load balancing is load distribution. Kubernetes uses two methods of load distribution. Both of them are easy to implement at the dispatch level and operate through the kube-proxy feature.
From the Service type drop-down list, select Node port. Click Expose. When your Service is ready, the Service details page opens, and you can see details about your Service. Under Ports, make a note of the Node Port that Kubernetes assigned to your Service.
A downwardAPI volume can expose Pod fields and container fields. In Kubernetes, there are two ways to expose Pod and container fields to a running container: Environment variables.
NodePort definitions have the same mandatory properties as ClusterIP services. The only difference is the change to type: NodePort . The targetPort field is still required, as NodePorts are backed by a ClusterIP service. This will route traffic on port 32000 to port 80 in your Pods.
You can deploy an Ingress configured to use the host network and port 80/443.
DO's firewall for your cluster doesn't have 80/443 inbound open by default.
If you edit the auto-created firewall the rules will eventually reset themselves. The solution is to create a separate firewall also pointing at the same Kubernetes worker nodes:
$ doctl compute firewall create \ --inbound-rules="protocol:tcp,ports:80,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:443,address:0.0.0.0/0,address:::/0" \ --tag-names=k8s:CLUSTER_UUID \ --name=k8s-extra-mycluster
(Get the CLUSTER_UUID
value from the dashboard or the ID column from doctl kubernetes cluster list
)
EDIT: The Helm chart in the above link has been DEPRECATED, Therefore the correct way of installing the chart would be(as per the new docs) is :
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update
After this repo is added & updated
# For Helm 2 $ helm install stable/nginx-ingress --name=myingress -f myingress.values.yml # For Helm 3 $ helm install myingress stable/nginx-ingress -f myingress.values.yml #EDIT: The New way to install in helm 3 helm install myingress ingress-nginx/ingress-nginx -f myingress.values.yaml
myingress.values.yml
for the chart:
--- controller: kind: DaemonSet hostNetwork: true dnsPolicy: ClusterFirstWithHostNet daemonset: useHostPort: true service: type: ClusterIP rbac: create: true
you should be able to access the cluster on :80 and :443 via any worker node IP and it'll route traffic to your ingress.
since node IPs can & do change, look at deploying external-dns to manage DNS entries to point to your worker nodes. Again, using the helm chart and assuming your DNS domain is hosted by DigitalOcean (though any supported DNS provider will work):
# For Helm 2 $ helm install --name=mydns -f mydns.values.yml stable/external-dns # For Helm 3 $ helm install mydns stable/external-dns -f mydns.values.yml
mydns.values.yml
for the chart:
--- provider: digitalocean digitalocean: # create the API token at https://cloud.digitalocean.com/account/api/tokens # needs read + write apiToken: "DIGITALOCEAN_API_TOKEN" domainFilters: # domains you want external-dns to be able to edit - example.com rbac: create: true
--- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: testing123-ingress annotations: kubernetes.io/ingress.class: nginx spec: rules: - host: testing123.example.com # the domain you want associated http: paths: - path: / backend: serviceName: testing123-service # existing service servicePort: 8000 # existing service port
$ dig testing123.example.com # should return worker IP address $ curl -v http://testing123.example.com # should send the request through the Ingress to your backend service
(Edit: editing the automatically created firewall rules eventually breaks, add a separate firewall instead).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With