如何在Kubernates Cron Jobs中使用卷曲响应
我们在Kubernetes群集中部署了一组Spring Boot应用程序。对于其中的一些,我们设计了以所需的频率触发的玉米作业,在这种频率上我们确实触发了已经开发的特定内部API。要求是使用API生成令牌,并通过生成的令牌作为身份验证。为了做同样的事情,我考虑使用卷发击中API,但不确定如何使用卷曲的响应并使用该令牌将其传递为后续卷曲请求中的授权标头。与令牌一起,我还需要发送我们拥有的API键,但我正在寻找一种以加密方式存储它的方法,然后将其解码在Cron Job中,然后再进行API命中。
apiVersion: batch/v1
kind: CronJob
metadata:
name: api-cron
spec:
# At 08:00 on Tuesday
schedule: "0 08 * * 2"
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
containers:
- command: ["/bin/sh", "-c"]
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
args:
- |
curl -s -i \
-X POST "http://application.$POD_NAMESPACE.svc.cluster.local/endpoint" \
-d ""
name: curl
image: curlimages/curl:7.80.0
We have a set of spring boot applications deployed in the Kubernetes cluster. For a few of them, we have designed the corn jobs which get triggered at the required frequency which is working fine in which we do hit our specific internal API that has been developed. The requirement is to generate a token using the API and pass the generated token as authentication. To do the same I am thinking of hitting the API using curl but not sure how I can use the response from curl and use that token to pass as an Authorization header in the subsequent curl request. Along with token, I do also need to send API Keys that we have but I am searching for a way to store it in an encrypted way and decode it in cron job before making an API hit.
apiVersion: batch/v1
kind: CronJob
metadata:
name: api-cron
spec:
# At 08:00 on Tuesday
schedule: "0 08 * * 2"
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
containers:
- command: ["/bin/sh", "-c"]
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
args:
- |
curl -s -i \
-X POST "http://application.$POD_NAMESPACE.svc.cluster.local/endpoint" \
-d ""
name: curl
image: curlimages/curl:7.80.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写一个shell脚本并将其作为容器CMD或入口点运行。将逻辑包括在shell脚本中。
Write a shell script and run it as container CMD or entrypoint. include the logic in the shell script.