<p>I have three different images related to my application which works fine in docker-compose and has issues running on kubernetes cluster in GCP. </p>

<p>Below is the deployment file. </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql-database
spec:
  type: NodePort
  ports:
    - port: 3306
      targetPort: 3306      
  selector:
    app: mysql-database
    tier: database
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql-database
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql-database
        tier: database
    spec:
      hostname: mysql
      containers:
        - image: mysql/mysql-server:5.7
          name: mysql
          env:
            - name: "MYSQL_USER"
              value: "root"
            - name: "MYSQL_HOST"
              value: "mysql"
            - name: "MYSQL_DATABASE"
              value: "xxxx"
            - name: "MYSQL_PORT"
              value: "3306"
            - name: "MYSQL_PASSWORD"
              value: "password"
            - name: "MYSQL_ROOT_PASSWORD"
              value: "password"
            - name: "RAILS_ENV"
              value: "production"
          ports:
            - containerPort: 5432
              name: db
---
apiVersion: v1
kind: Service
metadata:
  name: dgservice
  labels:
    app: dgservice
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
  selector:
    name: dgservice
    tier: dgservice
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: dgservice
  labels:
    app: dgservice
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: dgservice
        tier: dgservice
    spec:
      hostname: dgservice
      containers:
        - image: gcr.io/sample/sample-image:check_1
          name: dgservice
          ports:
            - containerPort: 8080
              name: dgservice
---
apiVersion: v1
kind: Service
metadata:
  name: dg-ui
  labels:
    name: dg-ui
spec:
  type: NodePort
  ports:
    - nodePort: 30156 
      port: 8000
      protocol: TCP
      targetPort: 8000
  selector:
    app: dg-ui
    tier: dg
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: dg-ui
  labels:
    app: dg-ui
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: dg-ui
        tier: dg
    spec:
      hostname: dg-ui
      containers:
        - image: gcr.io/sample/sample:latest
          name: dg-ui
          env:
            - name: "MYSQL_USER"
              value: "root"
            - name: "MYSQL_HOST"
              value: "mysql"
            - name: "MYSQL_DATABASE"
              value: "xxxx"
            - name: "MYSQL_PORT"
              value: "3306"
            - name: "MYSQL_PASSWORD"
              value: "password"
            - name: "MYSQL_ROOT_PASSWORD"
              value: "password"
            - name: "RAILS_ENV"
              value: "production"
            - name: "DG_SERVICE_HOST"
              value: "dgservice"
          ports:
            - containerPort: 8000
              name: dg-ui
</code></pre>

<p>The image is being pulled successfully from GCR as well. </p>

<p>The connection between mysql and ui service also works fine and my data's are getting migrated without any issues. But the connection is not established between the service and the ui. </p>

<p>Why ui is not able to access service in my application?</p>

klee
<p>As your deployment has the following lables so service need to have same labels in order to create endpoint object </p>

<p><strong>endpoints</strong> are the API object behind a service. The endpoints are where a service will route connections to when a connection is made to the ClusterIP of a service</p>

<p>Following are the labels of deployments</p>

<pre><code>      labels:
        app: dgservice
        tier: dgservice
</code></pre>

<p>New Service definition with <strong>correct labels</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: dgservice
  labels:
    app: dgservice
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
  selector:
    app: dgservice
    tier: dgservice
</code></pre>
