<pre><code> apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql
          ports:
            - containerPort: 3306
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: secretssql
                  key: pass
          volumeMounts:
            - name: mysqlvolume
              mountPath: &quot;/var/lib/mysql&quot;
      volumes:
        - name: mysqlvolume
          persistentVolumeClaim:
            claimName: sqlpvc
---
apiVersion: v1
kind: Secret
metadata:
  name: secretssql
data:
  # You can include additional key value pairs as you do with Opaque Secrets
  pass: YWRtaW4=

---
apiVersion: v1
kind: Service
metadata:
  name: sqlservice
spec:
  selector:
    app: mysql
  ports:
    - port: 80
   
</code></pre>
<h2>I want to connect to sql container using service sqlservice. Dns is reachable but when I try to ping the service,100% packet loss.</h2>
<p>I want to connect to sql container using service sqlservice. Dns is reachable but when I try to ping the service,100% packet loss.I want to connect to sql container using service sqlservice.</p>

Amarjeet
<p>Your service is using port 80:</p>
<pre><code>  ports:
    - port: 80
</code></pre>
<p>while your pod is listening on port 3306:</p>
<pre><code>ports:
  - containerPort: 3306
</code></pre>
<p>Try adjusting your service to user port 3306:</p>
<pre><code>  ports:
    - port: 3306
      targetPort: 3306
</code></pre>
