<p>We are using Linkerd 2.11.1 on Azure AKS Kubernetes. Amongst others there is a Deployment using using an Alpine Linux image containing Apache/mod_php/PHP8 serving an API. HTTPS is resolved by Traefik v2 with cert-manager, so that in coming traffic to the APIs is on port 80. The Linkerd proxy container is injected as a Sidecar.</p>
<p>Recently I saw that the API containers return 504 errors during a short period of time when doing a Rolling deployment. In the Sidecars log, I found the following :</p>
<pre><code>[ 0.000590s] INFO ThreadId(01) linkerd2_proxy::rt: Using single-threaded proxy runtime
[ 0.001062s] INFO ThreadId(01) linkerd2_proxy: Admin interface on 0.0.0.0:4191
[ 0.001078s] INFO ThreadId(01) linkerd2_proxy: Inbound interface on 0.0.0.0:4143
[ 0.001081s] INFO ThreadId(01) linkerd2_proxy: Outbound interface on 127.0.0.1:4140
[ 0.001083s] INFO ThreadId(01) linkerd2_proxy: Tap interface on 0.0.0.0:4190
[ 0.001085s] INFO ThreadId(01) linkerd2_proxy: Local identity is default.my-api.serviceaccount.identity.linkerd.cluster.local
[ 0.001088s] INFO ThreadId(01) linkerd2_proxy: Identity verified via linkerd-identity-headless.linkerd.svc.cluster.local:8080 (linkerd-identity.linkerd.serviceaccount.identity.linkerd.cluster.local)
[ 0.001090s] INFO ThreadId(01) linkerd2_proxy: Destinations resolved via linkerd-dst-headless.linkerd.svc.cluster.local:8086 (linkerd-destination.linkerd.serviceaccount.identity.linkerd.cluster.local)
[ 0.014676s] INFO ThreadId(02) daemon:identity: linkerd_app: Certified identity: default.my-api.serviceaccount.identity.linkerd.cluster.local
[ 3674.769855s] INFO ThreadId(01) inbound:server{port=80}: linkerd_app_inbound::detect: Handling connection as opaque timeout=linkerd_proxy_http::version::Version protocol detection timed out after 10s
</code></pre>
<p>My guess is that this detection leads to the 504 errors somehow. However, if I add the linkerd inbound port annotation to the pod template (terraform syntax):</p>
<pre><code>resource &quot;kubernetes_deployment&quot; &quot;my_api&quot; {
  metadata {
    name = &quot;my-api&quot;
    namespace = &quot;my-api&quot;
    labels = {
      app = &quot;my-api&quot;
    }
  }

  spec {
    replicas = 20
    selector {
      match_labels = {
        app = &quot;my-api&quot;
      }
    }
    template {
      metadata {
        labels = {
          app = &quot;my-api&quot;
        }
        annotations = {
          &quot;config.linkerd.io/inbound-port&quot; = &quot;80&quot;
        }
      }
</code></pre>
<p>I get the following:</p>
<pre><code>time=&quot;2022-03-01T14:56:44Z&quot; level=info msg=&quot;Found pre-existing key: /var/run/linkerd/identity/end-entity/key.p8&quot;
time=&quot;2022-03-01T14:56:44Z&quot; level=info msg=&quot;Found pre-existing CSR: /var/run/linkerd/identity/end-entity/csr.der&quot;
[ 0.000547s] INFO ThreadId(01) linkerd2_proxy::rt: Using single-threaded proxy runtime
thread 'main' panicked at 'Failed to bind inbound listener: Os { code: 13, kind: PermissionDenied, message: &quot;Permission denied&quot; }', /github/workspace/linkerd/app/src/lib.rs:195:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</code></pre>
<p>Can somebody tell me why it fails to bind the inbound listener?</p>
<p>Any help is much appreciated,</p>
<p>thanks,</p>
<p>Pascal</p>

Pascal Paulis
<p>Found it : Kubernetes sends asynchronuously requests to shutdown the pods and to no longer send traffic to them. And if the pod shuts down faster than it's removal from the IP lists, it can receive requests when already being dead.</p>
<p>To fix this, I added a <code>preStop</code> lifecycle hook to the application container:</p>
<pre><code>lifecycle {
    pre_stop {
        exec {
            command = [&quot;/bin/sh&quot;, &quot;-c&quot; , &quot;sleep 5&quot;]
        }
    }
}
</code></pre>
<p>and the following annotation to pod template :</p>
<pre><code>annotations = {
    &quot;config.alpha.linkerd.io/proxy-wait-before-exit-seconds&quot; = &quot;10&quot;
}
</code></pre>
<p>Documented here :</p>
<p><a href="https://linkerd.io/2.11/tasks/graceful-shutdown/" rel="nofollow noreferrer">https://linkerd.io/2.11/tasks/graceful-shutdown/</a></p>
<p>and here :</p>
<p><a href="https://blog.gruntwork.io/delaying-shutdown-to-wait-for-pod-deletion-propagation-445f779a8304" rel="nofollow noreferrer">https://blog.gruntwork.io/delaying-shutdown-to-wait-for-pod-deletion-propagation-445f779a8304</a></p>
