How to expose Kubernetes services to the public using DNS Load Balancing
Kubernetes Services in CloudFleet Kubernetes Engine (CFKE) are exposed via a DNS load balancing mechanism. All services get a unique DNS name in the format:
<service_name>.<cluster_id>.cfke.cloudfleet.dev
This DNS name resolves to the external IP of the Ingress controller, which acts as a load balancer to distribute incoming traffic to the appropriate service endpoints.
Note: Cloudfleet relies on nodes having an external IP set. If an external IP is not set, for example, in certain private networking configurations or self-managed on-premises Kubernetes nodes, Cloudfleet will default to using the private IP. This ensures that your service is accessible whether from within the cluster or from outside, provided that appropriate networking rules are in place. See Exposing applications to the Internet for more information.
Expose a web server using Kubernetes
Here’s a simple example of how to expose a web server using Kubernetes:
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld
labels:
app: helloworld
spec:
replicas: 1
selector:
matchLabels:
app: helloworld
template:
metadata:
labels:
app: helloworld
spec:
containers:
- name: webserver
image: paulbouwer/hello-kubernetes:1.10
ports:
- containerPort: 8080
env:
- name: MESSAGE
value: "Hello, I'm running on Cloudfleet!"
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: KUBERNETES_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: KUBERNETES_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
resources:
limits:
cpu: 50m
memory: 100Mi
requests:
cpu: 10m
memory: 15Mi
---
apiVersion: v1
kind: Service
metadata:
name: helloworld
labels:
app: helloworld
spec:
type: NodePort
selector:
app: helloworld
ports:
- name: http
port: 8080
targetPort: 8080
protocol: TCP
nodePort: 30080
In this example:
- The Nginx web server is deployed using a
Deployment
. - A
Service
of typeNodePort
exposes it externally, and will be accessible viahttp://helloworld.<cluster_id>.cfke.cloudfleet.dev:30080
.
To use your custom domain, and particularly if you want to use HTTPS, you need to set up a CNAME record in your DNS provider that points to the helloworld.<cluster_id>.cfke.cloudfleet.dev
domain.