<p>I am creating deployments using Kubernetes API from my server. The deployment pod has two containers - one is the main and the other is a sidecar container that checks the health of the pod and calls the server when it becomes healthy.</p>
<p>I am using <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#read-status-deployment-v1-apps" rel="noreferrer">this</a> endpoint to get the deployment. It has deployment status property with the following structure as mention <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#deploymentstatus-v1-apps" rel="noreferrer">here</a>.</p>
<p>I couldn't understand the fields <code>availableReplicas</code>, <code>readyReplicas</code>, <code>replicas</code>, <code>unavailableReplicas</code> and <code>updatedReplicas</code>.</p>
<p>I checked docs of Kubernetes and these SO questions too - <a href="https://stackoverflow.com/q/51085740/11642727">What is the difference between current and available pod replicas in kubernetes deployment?</a> and <a href="https://stackoverflow.com/q/39606728/11642727">Meaning of &quot;available&quot; and &quot;unavailable&quot; in kubectl describe deployment</a> but could not infer the difference between of a pod being ready, running and available. Could somebody please explain the difference between these terms and states?</p>

<p>A different kinds of <code>replicas</code> in the Deployment's Status can be described as follows:</p>
<ul>
<li><p><code>Replicas</code> - describes how many pods this deployment should have. It is copied from the spec. This happens asynchronously, so in a very brief interval, you could read a Deployment where the <code>spec.replicas</code> is not equal to <code>status.replicas</code>.</p>
</li>
<li><p><code>availableReplicas</code> - means how many pods are ready for at least some time (<code>minReadySeconds</code>). This prevents flapping of state.</p>
</li>
<li><p><code>unavailableReplicas</code> - is the total number of pods that should be there, minus the number of pods that has to be created, or ones that are not available yet (e.g. are failing, or are not ready for <code>minReadySeconds</code>).</p>
</li>
<li><p><code>updatedReplicas</code> - the number of pods reachable by deployment, that match the spec template.</p>
</li>
<li><p><code>readyReplicas</code> - the number of pods that are reachable from deployment through all the replicas.</p>
</li>
</ul>
<p>Let's use the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment" rel="noreferrer">official example</a> of a Deployment that creates a ReplicaSet to bring up three nginx Pods:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
</code></pre>
<p>The Deployment creates three replicated Pods, indicated by the <code>.spec.replicas</code> field.</p>
<p>Create the Deployment by running the following command:</p>
<pre><code>kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
</code></pre>
<p>Run <code>kubectl get deployments</code> to check if the Deployment was created.</p>
<p>If the Deployment is still being created, the output is similar to the following:</p>
<pre><code>NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0/3     0            0           1s
</code></pre>
<p>When you inspect the Deployments in your cluster, the following fields are displayed:</p>
<ul>
<li><p><code>NAME</code> - lists the names of the Deployments in the namespace.</p>
</li>
<li><p><code>READY</code> - displays how many replicas of the application are available to your users. It follows the pattern ready/desired.</p>
</li>
<li><p><code>UP-TO-DATE</code> - displays the number of replicas that have been updated to achieve the desired state.</p>
</li>
<li><p><code>AVAILABLE</code> - displays how many replicas of the application are available to your users.</p>
</li>
<li><p><code>AGE</code> - displays the amount of time that the application has been running.</p>
</li>
</ul>
<p>Run the <code>kubectl get deployments</code> again a few seconds later. The output is similar to this:</p>
<pre><code>NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           18s
</code></pre>
<p>To see the ReplicaSet (<code>rs</code>) created by the Deployment, run <code>kubectl get rs</code>. The output is similar to this:</p>
<pre><code>NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-75675f5897   3         3         3       18s
</code></pre>
<p>ReplicaSet output shows the following fields:</p>
<ul>
<li><p><code>NAME</code> - lists the names of the ReplicaSets in the namespace.</p>
</li>
<li><p><code>DESIRED</code> - displays the desired number of replicas of the application, which you define when you create the Deployment. This is the desired state.</p>
</li>
<li><p><code>CURRENT</code> - displays how many replicas are currently running.</p>
</li>
<li><p><code>READY</code> displays how many replicas of the application are available to your users.</p>
</li>
<li><p><code>AGE</code> - displays the amount of time that the application has been running.</p>
</li>
</ul>
<p>As you can see there is no actual difference between <code>availableReplicas</code> and <code>readyReplicas</code> as both of those fields displays how many replicas of the application are available to your users.</p>
<p>And when it comes to the <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/" rel="noreferrer">Pod Lifecycle</a> it is important to see the difference between <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase" rel="noreferrer">Pod phase</a>, <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-states" rel="noreferrer">Container states</a> and <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions" rel="noreferrer">Pod conditions</a> which all have different meanings. I strongly recommend going through the linked docs in order to get a solid understanding behind them.</p>
