How to configure DNS for Services and Pods in Kubernetes?
I have been going through the K8s documentation on DNS for Services and Pods. The main task that I want to resolve is my K8s deployment has NodePort
as service type. Meaning, I use the external IP addresses from the nodes to expose the service to the Internet. When I do this, my IP address is getting exposed and would rather prefer to have a hostname [ a DNS name]. Going through the documentation linked above, I do not understand much of the concepts owing to that fact that I'm new to K8s.
I have set-up Ingress Controller from NGINX for Bare Metal K8s because my cloud provider does not provide load balancing service.
So my question is: How do I set-up an ExternalDNS in my K8s cluster?
For reference purposes, these are my resources inside the K8s cluster.
Namespaces
NAME STATUS AGE
default Active 3d12h
ingress-nginx Active 5h53m
kube-node-lease Active 3d12h
kube-public Active 3d12h
kube-system Active 3d12h
Basically, I have all my deployments inside the default
namespace.
kubectl get all -n default
NAME READY STATUS RESTARTS AGE
pod/hello-docker-cc749b757-qfctr 1/1 Running 0 70m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/hello-docker NodePort 10.xxx.xxx.xxx <none> 3000:30072/TCP 70m
service/kubernetes ClusterIP 10.xxx.xxx.xxx <none> 443/TCP 3d12h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/hello-docker 1/1 1 1 70m
NAME DESIRED CURRENT READY AGE
replicaset.apps/hello-docker-cc749b757 1 1 1 70m
And this is the manifest file I have for service and deployment of hello-docker
app:
apiVersion: v1
kind: Service
metadata:
name: hello-docker
labels:
app: hello-docker
spec:
type: NodePort
ports:
- port: 3000
targetPort: 8000
protocol: TCP
name: http
selector:
app: hello-docker
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-docker
labels:
app: hello-docker
spec:
replicas: 1
selector:
matchLabels:
app: hello-docker
template:
metadata:
labels:
app: hello-docker
spec:
imagePullSecrets:
- name: regcred
containers:
- name: hello-docker
image: sebastian/hello-docker:1.1
imagePullPolicy: Always
ports:
- containerPort: 8000
Any feedbacks and suggestions would be highly appreciated.
Solution 1:
I made this work by creating a Cloudflare Tunnel (previously called Argo Tunnel). A complete configuration documentation on the tunnel can be found here. I hope someone with similar issue finds this useful.