skip to Main Content

It seems that Azure Container Instances does not have a tcpSocket in its livenessProbe selection.

How should a replacement for it be created in Bash? (netcat or nc is not an option with current base container)

e.g. I have application running a TCP server in port 8777 and I can use following Bash command

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

to check that it is still running, but if I try to execute similar check in YAML

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

if fails with following error:

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

2

Answers


  1. Chosen as BEST ANSWER

    It seems that the command must be splitted to multiple parts. At least the following works

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

  2. In Azure Container Instances, You can make use of readiness probe as mentioned in this MS Document1 and also Liveness probe as mentioned in this MS Document2

    As mentioned in MS Document1 you can create a yaml file with readiness-probe.yaml with the code below:-

    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
    

    And Deploy it in Azure Container Instances by running this command in your CLI:-

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

    Output:- https://i.imgur.com/aYXTrdk.png

    To Deploy Liveness probe you can create include the liveness probe in your existing YAML file or create a new one by referring the 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
    

    Output:- https://i.imgur.com/aOEowsG.png https://i.imgur.com/QNqsQuf.png

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search