首页 文章

用args部署kubernetes

提问于
浏览
0

我一添加,

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

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

下面是完整的部署yaml .

  • apiVersion:apps / v1种类:部署元数据:标签:app:web name:web namespace:default spec:replicas:1 selector:matchLabels:app:web version:prod template:metadata:annotations:prometheus.io/scrape:'true'标签:app:web version:prod spec:containers: - args: - / bin / sh - '-c' - > - touch / tmp / healthy; touch / tmp / liveness;而真实;回声 . 睡1;完成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

1 回答

  • 1

    问题出在你的情况下 container is not found 完成后's task. You told to execute a shell script to your conatainer. And after doing that the container is finished. That'为什么你可以't see whether the files were created or not. Also it didn'吨放任何日志 . 因此,您需要在创建文件后保持容器存活 . 你可以通过放置无限循环来做到这一点 . 它来了:

    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并运行,

    $ 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
    

相关问题