<p>I am trying to send mail using sendgrid api and cronjob in k8s , I tried my python code in cloud function and it is running as expected however when I used my code to create GCR image and deploy it in a k8s cronjob i got an <code>urllib.error.URLError: &lt;urlopen error [Errno 104] Connection reset by peer&gt; </code>error</p>
<p><img src="https://i.stack.imgur.com/9OFNG.png" alt="enter image description here" /></p>
<p>Well i created a pod for debugging , here is my pod definition that uses my linux image :</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: notifier
spec:
  serviceAccountName: xxxxxxxxxxx
  containers:
    - name: test
      image: eu.gcr.io/xxxxxxxxxxxxxxxxxxxxxx:v1.4
      command: [ &quot;/bin/bash&quot;, &quot;-c&quot;, &quot;--&quot; ]
      args: [ &quot;while true; do sleep 30; done;&quot; ]
</code></pre>
<p>I know that I need to allow traffic (egress and ingress ) so that my pod can get traffic from api however i don't know how to do it , here is my cronjob definition :</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: zzzzzzzzzzzzzzz
spec:
  schedule: &quot;00 7 * * *&quot;
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 5
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      parallelism: 1
      backoffLimit: 0
      template:
        spec:
          restartPolicy: Never
          serviceAccountName: xxxxxxxxxx
          containers:
            - name: yyyyyyyyyyyyy
              image: eu.gcr.io/xxxxxxxxxxxxxxxxxxxxxxxx:v1.4
              resources:
                requests:
                  memory: &quot;512Mi&quot;
                  cpu: 1
                limits:
                  memory: &quot;1024Mi&quot;
                  cpu: 2

</code></pre>
<p>I am using kustomize k8s , GKE , python sendgrid api</p>
<p>thank you for your support</p>

<p>To communicate from/to sendgrid , you need to add dns confs so that sendgrid api will be recognized , you need to open port (pod level) , I abandoned the sendgrid and I used the company's smtp server.</p>
