title: Kubernetes Service connection refused
body: <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 <a href="http://random-generator-svc:5050/" rel="nofollow noreferrer">http://random-generator-svc:5050/</a> 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: "TCP"
         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 wich specifies the Service and the Deployment of the "Caller" 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: "TCP"
      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 acess 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>