<p>I am designing a system with a single kubernetes deployment for multiple tenants, but there are multiple databases, queues etc. per customer. Anything stateless is shared, and anything with state is separate for each tenant. Based on the request host (tenant1.company.com or tenant2.company.com), the code will connect to the corresponding databases and queues.</p>

<p>How should readiness probes be designed in this case, where my pod is designed to work for multiple tenants?</p>

<p>I can think of the following options, none of which seem correct:</p>

<ol>
<li>Connect to all databases and queues and see if they are ready:
Disadvantage: this will cause pod to be not ready even if one
resource is down.</li>
<li>Connect to any one database and queue: Disadvantage: doesn't really check the readiness for all probes.</li>
<li>Do not have any readiness probe at all.</li>
</ol>

<p>It feels like if I have separation at resources level to support multiple tenants (this is a B2B multi-tenant, takes time and effort to onboard new tenant), I also need to have separation at Kubernetes deployment level.</p>

<p>Is this the standard approach - either have complete separation at all levels, or have one single unified system with same shared resources? If not, how do I design the readiness probes?</p>

Narayana
<p>As per my understanding, you are trying to extend Kubernetes Pod's readiness probe to reflect Application health for specific tenant. Unfortunately, Readiness probe is not designed for that.</p>

<p>The only purpose of Kubernetes readiness probe (even the new feature <code>Pod Ready++</code>) is to reflect the certain Pod ability to serve the traffic. Deployment and StatefulSet controllers take into account Pod readiness state during the rolling-update process.  </p>

<p>You can brake the whole update mechanics if you set the readiness probe to depend on external to the Pod components or a network endpoints connectivity.
 The correct way of using Readiness probe is to check only the Pod's internal components' conditions.</p>

<p>Kubernetes documentation pages:</p>

<ul>
<li><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes" rel="nofollow noreferrer">Define readiness probes</a></li>
<li><a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions" rel="nofollow noreferrer">Pod conditions and Container probes</a></li>
<li><a href="https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/0007-pod-ready%2B%2B.md" rel="nofollow noreferrer">Pod Ready++</a></li>
</ul>

<p>For certain simple application or microservices that only contains one Pod, it may reflect also the state of the application. But usually, application architecture is much more complex and contains many parts, each of which may have dependencies. </p>

<p>Sometimes it's cheaper and simpler to create your own health check loop in the frontend app (<code>www.example.com/healthz</code>) that reflects the whole App health, taking to account all its components statuses and their dependencies, or collect and aggregate JSON statuses from other components. </p>

<p>In Kubernetes world, components/apps are usually Services that balance the traffic to one or more Pods. Thus, a component is healthy if at least one Pod behind the corresponding Service is in Ready state. The number of Ready Pods behind the Service tells more about App Performance, than about the App Health.</p>

<p>As per my ability to imagine your App design:</p>

<ul>
<li>I would use several Ingress objects that make the traffic to be forwarded to the dedicated for each tenant frontend, in the tenant's <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/" rel="nofollow noreferrer">Namespace</a>. All other tenant's resources are also deployed there. </li>
<li>All shared components I would put in the additional Namespace, let's say "shared/static/commmon/stateless" and create <a href="https://kubernetes.io/docs/concepts/services-networking/service/#externalname" rel="nofollow noreferrer">ExternalName service</a> in each tenant's Namespace to access them (or Ingress if I would serve this content on a specific URL path). </li>
<li>I would also deploy some solution for Application+cluster monitoring.</li>
</ul>

<p>This way you can easily scale application parts if some tenant needs more resources.<br>
To manage deployments I would use <a href="https://www.coveros.com/what-is-a-helm-chart-a-beginners-guide/" rel="nofollow noreferrer">Helm charts</a>. This way I can easily deploy one more tenant or remove/update the existing one.</p>

<p>There are many different solutions to monitor an Application Health, Performance, collect metrics and logs and take actions if certain conditions are met. It's just a brief list of most popular solutions:</p>

<ul>
<li><a href="https://metrics.dropwizard.io/4.1.2/manual/healthchecks.html" rel="nofollow noreferrer">Metrics Framework (Java)</a></li>
<li><a href="https://github.com/prometheus/prometheus" rel="nofollow noreferrer">Prometheus</a></li>
<li><a href="https://platform9.com/blog/kubernetes-logging-and-monitoring-the-elasticsearch-fluentd-and-kibana-efk-stack-part-1-fluentd-architecture-and-configuration/" rel="nofollow noreferrer">EFK stack</a></li>
<li><a href="https://github.com/jaegertracing/jaeger" rel="nofollow noreferrer">Jaeger</a></li>
<li><a href="https://istio.io/" rel="nofollow noreferrer">Istio</a></li>
<li><a href="https://github.com/weaveworks/scope" rel="nofollow noreferrer">Weave Scope</a></li>
<li><a href="https://www.datadoghq.com/dg/monitor/kubernetes-monitoring-benefits/?utm_source=Advertisement&amp;utm_medium=GoogleAdsNon1stTier&amp;utm_campaign=GoogleAdsNon1stTier-Kubernetes&amp;utm_content=Kubernetes&amp;utm_keyword=%2Bkubernetes%20%2Bmonitor&amp;utm_matchtype=b&amp;gclid=EAIaIQobChMI-enkkKjo6AIVxI2yCh3jewHTEAAYASAAEgLPdPD_BwE" rel="nofollow noreferrer">Datadog Realtime Kubernetes Monitoring</a></li>
<li>Cloud specific tools like Google Cloud's operations suite (formerly Stackdriver)</li>
<li>many more...</li>
</ul>

<p>PS: In case you want to implement a circuit breaker for the tenants, Istio has <a href="https://developers.redhat.com/blog/2018/03/27/istio-circuit-breaker-when-failure-is-an-option/" rel="nofollow noreferrer">built-in functionality</a>.</p>
