使用sendgrid和kubernates cronjob发送邮件
我正在尝试使用 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
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从/到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.