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

标签 bash azure yaml azure-container-instances

看来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/

相关文章:

bash - 调用 readline 绑定(bind)命令后刷新 Bash 提示符

regex - 带有输入和输出文件的单个重复命令

linux - grep 多个文件上的多个字符串

go - 使用 Go 读写 Yaml 文件

xml - 嵌入式设备GUI设计工具

bash - 在 shell 脚本中按日期删除文件?

azure - KQL 中的 `!has` 和 `!has_cs` 字符串运算符有什么区别?

azure - Kusto 无法将值投影到用户定义的函数中

azure - 从 ARM 模板中的 customData (cloud-init) 部分访问 keyvault 中的 secret

Ansible 回显到文件中