gpt4 book ai didi

bash - 如何在 Bash 中为 Azure 容器实例创建 tcp Socket liveness Probe 替代品?

转载 作者:行者123 更新时间:2023-12-03 03:23:16 25 4
gpt4 key购买 nike

看来Azure容器实例does not have livenessProbe 选择中的 tcpSocket。

如何在 Bash 中创建它的替代品? (netcatnc 不是当前基础容器的选项)

例如我有一个应用程序在端口 8777 上运行 TCP 服务器,我可以使用以下 Bash 命令

timeout 1 bash -c 'cat < /dev/null > /dev/tcp/127.0.0.1/8777'

检查它是否仍在运行,但如果我尝试在 YAML 中执行类似的检查

livenessProbe:
exec:
command:
- /bin/bash -c "timeout 1 bash -c 'cat < /dev/null > /dev/tcp/127.0.0.1/8777'"

如果失败并出现以下错误:

Liveness probe failed: to exec in container: failed to start exec "fafa...": quest RPC failure: failed to run runc create/exec call for container b12de... with exit status 1: exec failed: container_linux.go:380: starting container process caused: exec: "/bin/bash -c \"timeout 1 bash -c 'cat < /dev/null > /dev/tcp/127.0.0.1/8107'\"": stat /bin/bash -c "timeout 1 bash -c 'cat < /dev/null > /dev/tcp/127.0.0.1/8107'": no such file or directory: unknown

最佳答案

在 Azure 容器实例中,您可以使用就绪探针,如本 MS Document1 中所述。以及此MS Document2中提到的 active 探针

MS Document1 中所述您可以使用 readiness-probe.yaml 创建一个 yaml 文件,代码如下:-

apiVersion: 2019-12-01 location: eastus name: readinesstest
properties: containers:
- name: mycontainer
properties:
image: mcr.microsoft.com/azuredocs/aci-helloworld
command:
- "/bin/sh"
- "-c"
- "node /usr/src/app/index.js & (sleep 240; touch /tmp/ready); wait"
ports:
- port: 80
resources:
requests:
cpu: 1.0
memoryInGB: 1.5
readinessProbe:
exec:
command:
- "cat"
- "/tmp/ready"
periodSeconds: 5 osType: Linux restartPolicy: Always ipAddress:
type: Public
ports:
- protocol: tcp
port: '80' tags: null type: Microsoft.ContainerInstance/containerGroup

并通过在 CLI 中运行以下命令将其部署在 Azure 容器实例中:-

az container create --resource-group rg-name --file readiness-probe.yaml

输出:- https://i.imgur.com/aYXTrdk.png

要部署活跃度探测器,您可以将活跃度探测器包含在现有的 YAML 文件中,或者通过引用 MS Document2 创建一个新的探测器。

liveness.yaml:-

apiVersion: 2019-12-01 location: eastus name: livenesstest properties:
containers:
- name: mycontainer
properties:
image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
command:
- "/bin/sh"
- "-c"
- "touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600"
ports: []
resources:
requests:
cpu: 1.0
memoryInGB: 1.5
livenessProbe:
exec:
command:
- "cat"
- "/tmp/healthy"
periodSeconds: 5 osType: Linux restartPolicy: Always tags: null type: Microsoft.ContainerInstance/containerGroups
az container create --resource-group rg name --file liveness.yaml

输出:- https://i.imgur.com/aOEowsG.png https://i.imgur.com/QNqsQuf.png

关于bash - 如何在 Bash 中为 Azure 容器实例创建 tcp Socket liveness Probe 替代品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76280443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com