使用sendgrid和kubernates cronjob发送邮件

发布于 2025-01-18 18:06:20 字数 1465 浏览 4 评论 0原文

我正在尝试使用 k8s 中的 sendgrid api 和 cronjob 发送邮件,我在云函数中尝试了我的 python 代码,它按预期运行,但是当我使用我的代码创建 GCR 映像并将其部署在 k8s cronjob 中时,我得到了 urllib.error.URLError:错误

在此处输入图像描述

我创建了一个用于调试的 pod,这是使用我的 linux 的 pod 定义图片:

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;" ]

我知道我需要允许流量(出口和入口),以便我的 pod 可以从 api 获取流量,但是我不知道该怎么做,这是我的 cronjob 定义:

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

我正在使用 kustomize k8s、GKE、python sendgrid api

感谢您的支持

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2025-01-25 18:06:20

要从/到SendGrid进行通信,您需要添加DNS Confs,以便可以识别SendGrid API,您需要打开端口(POD级别),我放弃了SendGrid,我使用了公司的SMTP服务器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文