1

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 urllib.error.URLError: <urlopen error [Errno 104] Connection reset by peer> error

enter image description here

Well i created a pod for debugging , here is my pod definition that uses my linux image :

apiVersion: v1
kind: Pod
metadata:
  name: notifier
spec:
  serviceAccountName: xxxxxxxxxxx
  containers:
    - name: test
      image: eu.gcr.io/xxxxxxxxxxxxxxxxxxxxxx:v1.4
      command: [ "/bin/bash", "-c", "--" ]
      args: [ "while true; do sleep 30; done;" ]

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 :

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: zzzzzzzzzzzzzzz
spec:
  schedule: "00 7 * * *"
  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: "512Mi"
                  cpu: 1
                limits:
                  memory: "1024Mi"
                  cpu: 2

I am using kustomize k8s , GKE , python sendgrid api

thank you for your support

itIsNaz
  • 621
  • 5
  • 11
  • The [Errno 104] Connection reset by peer error means that the TCP connection was interrupted. This could be due to a number of reasons. A simple one is just your internet connection going down for a moment. Another reason could be a firewall or proxy getting in the way. Please check your network configuration and try again. – Bakul Mitra Apr 04 '22 at 15:39
  • well this is what i read in the doc of sendgrid and i know that it is a question of port exposition however i d'ont knwo how to expose the pod so it can get egress and ingress data when communicating with sendgrid api – itIsNaz Apr 04 '22 at 15:54
  • Are you using a public or private GKE cluster? – Gari Singh Apr 05 '22 at 08:41
  • @itIsNaz are you using Private and Public GKE Cluster? If it is private whether you have Cloud NAT or other means to reach external resources? Is authentication used? connection reset by peer implies it may be a timeout (10s or more) or bad TLS handshake (certificate). – Bakul Mitra Apr 06 '22 at 03:44
  • It is a private cluster , the connection to my pod is blocked , I needed to add some dns configuration so that the communication to/from sendgrid wil be enabled , well I abandoned Sendgrid (I don't like thier solution) I iused finally my company's smtp server – itIsNaz Apr 12 '22 at 09:01

1 Answers1

1

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.

itIsNaz
  • 621
  • 5
  • 11