Score:1

How to configure DNS for Services and Pods in Kubernetes?

ru flag

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.

Mikolaj S. avatar
cn flag
Which version of Kubernetes did you use? Did you use bare metal installation or some cloud provider?
Sebastian avatar
ru flag
@MikolajS. I have used from a cloud provider. They have tutorial for initial K8s set-up with Ansible and Terraform but do not have LB service. With regard to the version, it is v1.21
Mikolaj S. avatar
cn flag
Do you have ready IP node and want to write a domain name - if so you should do it outside of kubernetes - depends of your procider - for example [Amazon Route 53](https://aws.amazon.com/route53/).
Wytrzymały Wiktor avatar
it flag
Hello @Sebastian. Any updates?
Sebastian avatar
ru flag
@WytrzymałyWiktor, nothing interesting, actually. To make it work, I set-up a Cloudflare Tunnel ( aka Argo Tunnel) which routes the traffic via ingress controller. The tunnel needs to be kept alive, so I made the tunnel to run through a VM instance in cloud. Now, the problem is I can access my DNS hostname but can't prevent the direct IP access.
kkopczak avatar
ng flag
If you made it work consider adding your solution as an answer and create new question with current problem.
Score:1
ru flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.