Kubernetes Service DNS Unreachable

7/15/2020

I am in the phase of learning Kubernetes, trying to create a service and reach it via ping / curl.

Step1: Created a deployment mytomcat in default namespace

alias k='kubectl'
k create deployment mytomcat --image=tomcat

Step2: Created a deployment busybox with curl in default namespace

apiVersion: v1
kind: Pod
metadata:
  name: mybusybox
  namespace: default
spec:
  containers:
  - image: yauritux/busybox-curl
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: busybox
  restartPolicy: Always

k apply -f busybox.yaml
k exec mybusybox -t -i -- sh

Step3: Ping the mytomcat pods and it works

ping 10.1.1.11
PING 10.1.1.11 (10.1.1.11): 56 data bytes
64 bytes from 10.1.1.11: seq=0 ttl=64 time=0.207 ms

Step4: Create a service to expose port 8080 on tomcat

k expose deployment mytomcat --port=8080 

Step5: Get stats of all resources

k get all -o wide
NAME                            READY   STATUS    RESTARTS   AGE   IP          NODE             NOMINATED NODE   READINESS GATES
pod/mybusybox                   1/1     Running   0          10m   10.1.1.14   docker-desktop   <none>           <none>
pod/mytomcat-6bfbf4c889-xqkg9   1/1     Running   0          39m   10.1.1.11   docker-desktop   <none>           <none>

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE     SELECTOR
service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP    42m     <none>
service/mytomcat     ClusterIP   10.102.120.90   <none>        8080/TCP   6m40s   app=mytomcat

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES   SELECTOR
deployment.apps/mytomcat   1/1     1            1           39m   tomcat       tomcat   app=mytomcat

NAME                                  DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES   SELECTOR
replicaset.apps/mytomcat-6bfbf4c889   1         1         1       39m   tomcat       tomcat   app=mytomcat,pod-template-hash=6bfbf4c889

Step7: curl the service to reach tomcat pod failed. Is this the expected output ? Cos it says Err code 404. I have no working idea of a tomcat server.

    curl http://mytomcat:8080
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/9.0.37</h3></body></html>/home

Can anyone advise where am I doing it wrong or suggest good resources to learn in simple to begin with.

Thank you.

-- Piyush
dns
kubernetes
tomcat

1 Answer

7/15/2020

This not a DNS Unreachable issue or DNS issue at all. This is expected since you have not deployed a war file on the tomcat hence HTTP Status 404 – Not Found

Please refer to this question on how to deploy a war file on tomcat running in kubernetes. https://stackoverflow.com/questions/54341432/deploy-war-in-tomcat-on-kubernetes

-- Arghya Sadhu
Source: StackOverflow