<p>I am trying to run a cron job in kubernetes that needs to access a database. This is the database yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    component: db
  name: db
spec:
  selector:
    matchLabels:
      component: db
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        component: db
    spec:
      containers:
        - name: db
          image: mysql:5.7
          ports:
            - containerPort: 3306
          args:
            - --transaction-isolation=READ-COMMITTED
            - --binlog-format=ROW
            - --max-connections=1000
            - --bind-address=0.0.0.0
          env:
            - name: MYSQL_DATABASE
              valueFrom:
                secretKeyRef:
                  key: MYSQL_DATABASE
                  name: db-secrets
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: MYSQL_PASSWORD
                  name: db-secrets
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: MYSQL_ROOT_PASSWORD
                  name: db-secrets
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  key: MYSQL_USER
                  name: db-secrets
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: db-persistent-storage
      restartPolicy: Always
      volumes:
        - name: db-persistent-storage
          persistentVolumeClaim:
            claimName: db-pvc
</code></pre>
<p>And this is the yaml for the cronjob:</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cron
spec:
  schedule: &quot;0 0 * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: cron
              image: iulbricht/shopware-status-tool:1.0.0
              env:
                - name: USERNAME
                  valueFrom:
                    secretKeyRef:
                      key: USERNAME
                      name: cron-secrets
                - name: PASSWORD
                  valueFrom:
                    secretKeyRef:
                      key: PASSWORD
                      name: cron-secrets
                - name: DATABASE_DSN
                  valueFrom:
                    secretKeyRef:
                      key: DATABASE_DSN
                      name: cron-secrets
                - name: DHL_API_KEY
                  valueFrom:
                    secretKeyRef:
                      key: DHL_API_KEY
                      name: cron-secrets
                - name: SHOP_API
                  valueFrom:
                    secretKeyRef:
                      key: SHOP_API
                      name: cron-secrets
          restartPolicy: OnFailure
</code></pre>
<p>When the cronjob runs I always get the following message: <code>default addr for network 'db:3306' unknown</code>. The mysql connection string is as follows: mysql://username:password@db:3306/shopware</p>
<p>I am using Kustomization and the db and cron are in the save namespace.</p>
<p>Can anyone help me find a way to solve this?</p>

Knerd
<p>Can you please try this connection string</p>
<pre><code>username:password@tcp(db:3306)/shopware
</code></pre>
