Kubernetes job doesn’t complete.

huangapple go评论62阅读模式
英文:

Kubernetes job doesn't complete

问题

关于您的问题,以下是翻译的内容:

作为练习,我编写了以下的任务来获取集群中所有Pod的名称、类型、命名空间和UID。

apiVersion: batch/v1
kind: Job
metadata:
name: get-info
spec:
template:
spec:
containers:
- name: get-info
image: busybox
command: ['sh', '-c', 'kubectl get all -o custom-columns=name:.metadata.name,type:.kind,namespace:.metadata.namespace,uid:.metadata.uid > ./data.json']
restartPolicy: Never


我不确定为什么,但这个任务从未完成。命令本身在命令行上直接运行时可以正常工作,但创建的Pod在创建后总是出现错误。

我该如何使其工作,以及以后如何调试这样的问题?

谢谢

编辑:也许我的方法不正确。我应该创建一个工作负载,将上述内容输出到JSON中。也许Job不是执行此操作的正确资源?

我尝试记录Pod,但失败了。使用"get pods"命令后,我看到每个创建的Pod的状态都是ERROR,就绪状态为0/1。
英文:

For an exercise, I wrote the following job to get the name, type, namespace and uid of all pods in the cluster

apiVersion: batch/v1
kind: Job
metadata:
  name: get-info
spec:
  template:
    spec:
      containers:
      - name: get-info
        image: busybox
        command: ['sh', '-c', 'kubectl get all -o custom-columns=name:.metadata.name,type:.kind,namespace:.metadata.namespace,uid:.metadata.uid > ./data.json']
      restartPolicy: Never

I'm not sure why, but the job never gets completed. The command itself works fine directly on the CLI, but the created pods always get an error after their creation.

How do I get it to work, and for future reference how do I debug such a problem?

Thanks

edit: Perhaps it's my approach that's incorrect. I'm supposed to create a workload that outputs the above into JSON. Is Job maybe not the correct resource to do this?

I tried logging the pods, but it failed. Upon using get pods I saw that every created pod had the status ERROR and ready 0/1.

答案1

得分: 1

你使用的镜像 busybox 没有安装 kubectl。请尝试:

containers:
- name: get-info
  image: bitnami/kubectl  # <-- 这个镜像带有 kubectl 命令

如果你对连接到服务器有疑问,可以查看这个 StackOverflow 问题

英文:

The image you used busybox doesn't come with kubectl installed. Try:

containers:
- name: get-info
  image: bitnami/kubectl  # <-- this image come with kubectl command

Checkout this stackoverflow question if you have doubt connecting to your server.

答案2

得分: -1

将这一行更改为:

command: ["/bin/sh"]
args: ["-c", "kubectl get all -o custom-columns=name:.metadata.name,type:.kind,namespace:.metadata.namespace,uid:.metadata.uid > ./data.json"]
英文:

Change this line:

 command: ['sh', '-c', 'kubectl get all -o custom-columns=name:.metadata.name,type:.kind,namespace:.metadata.namespace,uid:.metadata.uid > ./data.json']

To (notice two lines):

 command: ["/bin/sh"]
 args: ["-c", "kubectl get all -o custom-columns=name:.metadata.name,type:.kind,namespace:.metadata.namespace,uid:.metadata.uid > ./data.json"]

huangapple
  • 本文由 发表于 2023年6月12日 09:16:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76453147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定