<p>I want to create a sample application with Kubernetes but I get connection refused if I try to connect to the responsive service in Kubernetes.</p>
<p>For example if I connect from another pod to http://random-generator-svc:5050/ I get an error which says connection refused.</p>
<p>this is the yaml file to create the Service and the Deployment for the Random Generator:</p>
<pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: random-generator-svc
    labels:
      app: rand-gen
 spec:
   selector:
     app: rand-gen
     type: NodePort
     ports:
     - protocol: &quot;TCP&quot;
       port: 5050
       targetPort: 5050
       name: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: random-generator-deployment
  labels:
    app: rand-gen
spec:
  replicas: 2
  selector:
    matchLabels:
      app: rand-gen
  template:
    metadata:
    labels:
      app: rand-gen
  spec:
    containers:
    - name: random-generator-container
      image: toky03/random-generator-image:1.2
      ports:
      - containerPort: 5050
</code></pre>
<p>This is the yaml File which specifies the Service and the Deployment of the &quot;Caller&quot; Application:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: middle-tier-svc
  labels:
    app: rand-gen
spec:
  selector:
    app: rand-gen
  type: NodePort
  ports:
  - protocol: &quot;TCP&quot;
    port: 7070
    targetPort: 7070
    name: http

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: middle-tier-controller
  labels:
    app: rand-gen
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rand-gen
  template:
    metadata:
      labels:
        app: rand-gen
    spec:
      containers:
      - name: random-controller-container
        image: toky03/random-controller-image:1.2
        ports:
        - containerPort: 7070
</code></pre>
<p>I changed the type to <code>NodePort</code> to try if this error also exists there but I am able to access the service from outside of a cluster. Is there probably a problem with my Kubernetes DNS resolver?</p>
<p>Thank you very much in advance for your help.</p>

Marco Jakob
<p>By default, kubernetes creates a virtual proxy. You can then access your service after port forwarding it.</p>

<pre><code>kubectl port-forward svc random-generator-svc 5050:5050
</code></pre>
