<p>How do i provide a service with a dns name in the deployment file so that i can access that service from some other service from the same cluster?</p>

<pre><code>apiVersion: apps/v1
kind: Deployment

metadata:
  name: db
spec:
  selector:
    matchLabels:
      app: db
  replicas: 1
  template:
    metadata:
      labels:
        app: db
    spec:
      containers:
      - name: db
        image: mysql:5.7.29
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "root"
        volumeMounts:
        - mountPath: /var/log/mysql/
          name: mysql
      volumes:
      - name: mysql
        hostPath:
          path: "/home/sandeep/logs/mysql/"
---
apiVersion: v1
kind: Service
metadata:
  name: database
  labels:
    app: db
spec:
  selector:
    app: db
  type: ClusterIP
  ports:
  - name: database
    port: 3306
    targetPort: 3306

</code></pre>

<p>This is mysql deployment file so how can i provide this service with a dns name? In which do i need to make change?</p>

sandeep P
<p>Assuming that you created the database service in <code>default</code> namespace you can access mysql via <code>database.default.svc.cluster.local</code> from any namespace and via <code>database.svc.cluster.local</code> from the same namespace.</p>
