使用args进行Kubernetes部署 [英] kubernetes deployment with args

查看:1879
本文介绍了使用args进行Kubernetes部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加后,

spec:
    containers:
      - args:
          - /bin/sh
          - '-c'
          - touch /tmp/healthy; touch /tmp/liveness
        env:

对于部署文件,在描述日志中没有出现任何错误的情况下,应用程序不会启动.部署成功,但是没有输出.这两个文件都在容器中创建.我可以在kubernetes部署中运行docker build吗?

to the deployment file, the application is not coming up without any error in the description logs. The deployment succeed, but no output. Both files getting created in the container. Can I run docker build inside kubernetes deployment?

下面是完整的部署Yaml.

Below is the complete deployment yaml.

  apiVersion: apps/v1
  kind: Deployment
  metadata:
    labels:
      app: web
    name: web
    namespace: default
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: web
        version: prod
    template:
      metadata:
        annotations:
          prometheus.io/scrape: 'true'
        labels:
          app: web
          version: prod
      spec:
        containers:
          - args:
              - /bin/sh
              - '-c'
              - >-
                touch /tmp/healthy; touch /tmp/liveness; while true; do echo .;
                sleep 1; done
            env:
              - name: SUCCESS_RATE
                valueFrom:
                  configMapKeyRef:
                    key: SUCCESS_RATE
                    name: web-config-prod
            image: busybox
            livenessProbe:
              exec:
                command:
                  - cat
                  - /tmp/liveness
              initialDelaySeconds: 5
            name: web
            ports:
              - containerPort: 8080
              - containerPort: 8000

推荐答案

在您的情况下,问题是完成任务后的container is not found.您被告知要对容器执行Shell脚本.这样做之后,容器就完成了.这就是为什么您看不到文件是否已创建的原因.此外,它没有放置任何日志.因此,创建文件后,您需要保持容器活动.您可以通过放置一个无限的while循环来做到这一点.来了:

The problem was in your case is container is not found after finishing it's task. You told to execute a shell script to your conatainer. And after doing that the container is finished. That's why you can't see whether the files were created or not. Also it didn't put any logs. So you need to keep alive the container after creating the files. You can do that by putting a infinite while loop. Here it comes:

apiVersion: apps/v1
kind: Deployment
metadata:
name: hello
labels:
    app: hi
spec:
replicas: 1
selector:
    matchLabels:
    app: hi
template:
    metadata:
    labels:
        app: hi
    spec:
    containers:
    - name: hi
        image: busybox
        args:
        - /bin/sh
        - "-c"
        - "touch /tmp/healthy; touch /tmp/liveness; while true; do echo .; sleep 1; done"
        ports:
        - containerPort: 80

将其保存到hello-deployment.yaml并运行,

Save it to hello-deployment.yaml and run,

$ kubectl create -f hello-deployment.yaml
$ pod_name=$(kubectl get pods -l app=hi -o jsonpath='{.items[0].metadata.name}')
$ kubectl logs -f $pod_name
$ kubectl exec -it -f $pod_name -- ls /tmp

这篇关于使用args进行Kubernetes部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆