<p>After creating a service and an endpoint object -&gt;</p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: external-service
  namespace: default
spec:
  ports:
  - protocol: TCP
    port: 8200
---
apiVersion: v1
kind: Endpoints
metadata:
  name: external-service
subsets:
  - addresses:
      - ip: $EXTERNAL_ADDR
    ports:
      - port: 8200
</code></pre>
<p>How can I point to the service in the deployment.yaml file. I want to remove the hardcoded IP the env variable</p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: devwebapp
  labels:
    app: devwebapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: devwebapp
  template:
    metadata:
      labels:
        app: devwebapp
    spec:
      serviceAccountName: internal-app
      containers:
      - name: app
        image: app:k8s
        imagePullPolicy: Always
        env:
        - name: ADDRESS
          value: &quot;http://$EXTERNAL_SERVICE:8200&quot;
</code></pre>
<p>Simply changing the value to <code>http://external-service</code> didn't help.</p>
<p>Thank you in advance!</p>

anushjay
<p>you don't need to create endpoints separately just use <code>selector</code> in service <code>spec</code>. it will automatically create  desired endpoints.</p>
<p>this one will work for you:</p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: external-service
  namespace: default
spec:
  selector:
    app: devwebapp
  ports:
  - protocol: TCP
    port: 8200
</code></pre>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: devwebapp
  labels:
    app: devwebapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: devwebapp
  template:
    metadata:
      labels:
        app: devwebapp
    spec:
      serviceAccountName: internal-app
      containers:
      - name: app
        image: app:k8s
        imagePullPolicy: Always
        ports:
        - containerPort: 8200
        env:
        - name: ADDRESS
          value: http://external-service:8200
</code></pre>
