kubernetes 如何在使用stdin时使用kubectl run指定限制

cwxwcias  于 2023-04-29  发布在  Kubernetes
关注(0)|答案(2)|浏览(140)

我以这种方式(EKS环境)成功调用Kaniko(可以构建Docker镜像的Docker镜像):

cat build.tar.gz | kubectl run kaniko-httpd-ex --quiet --stdin --rm --restart=Never --image=748960220740.dkr.ecr.eu-west-1.amazonaws.com/kaniko:0 --env=AWS_SDK_LOAD_CONFIG=true -- --destination=748960220740.dkr.ecr.eu-west-1.amazonaws.com/httpd-ex:23-04-26_08-54-DV-6525-kube --context tar://stdin --label commit=8e3a236f702c689891a50a60acf7e05658fa3939 --label build_url=Sin-Jenkins

这可以正常工作,除非没有足够的临时存储可用。
现在我想指定限制,如ephemereal-storage。由于--limits选项在最近版本的Kubernetes中已经被删除,所以我必须使用--overrides,并且我必须改变很多东西。
我是这样做的:

cat build.tar.gz | kubectl run kaniko-httpd-ex --quiet --restart=Never -i --rm --image=748960220740.dkr.ecr.eu-west-1.amazonaws.com/kaniko:0 --overrides='{"apiVersion":"v1",
"spec":
{"containers":[{
  "name":"kaniko",
  "stdin": true,
  "restartPolicy":"Never",
  "image":"748960220740.dkr.ecr.eu-west-1.amazonaws.com/kaniko:0",
  "env":[{"name":"AWS_SDK_LOAD_CONFIG","value":"true"}],
  "resources":{"requests":{
    "ephemeral-storage":"116Mi",
    "memory": "50Mi",
    "cpu": "50m"
  }},
  "args":[
    "--destination=748960220740.dkr.ecr.eu-west-1.amazonaws.com/httpd-ex:23-04-26_08-57-DV-6525-kube",
    "--context","tar://stdin"
    ,"--label","commit=8e3a236f702c689891a50a60acf7e05658fa3939","--label","build_url=Sin-Jenkins"]
}]}'

它正确地启动了kaniko,但65秒后,kaniko被杀死,唯一的错误消息是:

error: timed out waiting for the condition
$ kubectl get ev | grep kaniko
19m         Normal   Scheduled   pod/kaniko-httpd-ex   Successfully assigned sbt-david/kaniko-httpd-ex to ip-10-120-134-171.eu-west-1.compute.internal
19m         Normal   Pulled      pod/kaniko-httpd-ex   Container image "748960220740.dkr.ecr.eu-west-1.amazonaws.com/kaniko:0" already present on machine
19m         Normal   Created     pod/kaniko-httpd-ex   Created container kaniko
19m         Normal   Started     pod/kaniko-httpd-ex   Started container kaniko
17m         Normal   Killing     pod/kaniko-httpd-ex   Stopping container kaniko

如何在使用stdin时指定资源限制?
相关信息:

备注:

  • 我不能使用kubectl run中的--limits标志,因为它最近被删除了。
rhfm7lfc

rhfm7lfc1#

您的样品:

...
"resources":{"requests":{
    "ephemeral-storage":"116Mi"},  # <-- incorrect
...

尝试:

...
"resources":{
  "requests":{
    "ephemeral-storage": "116Mi",
    "memory": "50Mi",
    "cpu": "50m"
  },
...

下面是一个运行5m的pod的工作示例。执行kubectl describe pod busybox并检查Requests部分:

kubectl run busybox --image busybox --overrides '
{
  "apiVersion": "v1",
  "spec": {
     "restartPolicy": "Never",
     "containers": [
      {
        "name": "busybox",
        "image": "busybox",
        "command": ["ash", "-c", "sleep 300"],
        "resources": {
          "requests":{
            "ephemeral-storage": "116Mi",
            "memory": "50Mi",
            "cpu": "50m"
 }}}]}}'
yws3nbqq

yws3nbqq2#

它运行正常,如果我这样做,我可以设置限制:

kubectl apply -f kaniko.yaml
kubectl wait pod/kaniko --for condition=Ready --timeout=10m
kubectl attach kaniko -i
kubectl get pod/$pod -o jsonpath='{.status.containerStatuses[*].state.terminated.exitCode}'

因此,对于高级用途,kubectl run并不合适,至少对于版本1是这样。27.1.

相关问题