<p>We have a data visualization server hosted in Kubernetes pods. The dashboards in that data viz are displayed in the browser of different monitors/terminals for near-real time operational reporting. Sometimes the pods fail, and when they come alive again, the browser redirects to Single Sign-On page instead of going to the dashboard the URL is originally configured to.</p>
<p>The server are hosted in I would presume a replica set. There are two pods that exist as far as I can tell.</p>
<p>I was granted privilege on using kubectl to solve this problem, but still quite new with the whole Kubernetes thing. Using kubectl, how do I simulate pod failure/restart for testing purposes? Since the pods are in duplicate, shutting one of them will only redirect the traffic to the other pod. How to make both pods fail/restart at the same time? (I guess doing <code>kubectl delete pod</code> on both pods will do, but I want to make sure k8s will respawn the pods automatically, and not delete them forever).</p>

oikonomiyaki
<p>If I understand the use case correctly, you might want to use <code>kubectl scale</code> command. This will give you the flexibility to make the replica count to zero to N by running a simple <code>kubectl scale</code> command.  See examples.  Also, if you are using deployment, you can just do the <code>kubectl delete</code> pod, the deployment controller will spawn a new one to satisfy the replica count.</p>
<pre><code>kubectl scale deployment/&lt;DEPLOYMENT-NAME&gt;  --replicas=&lt;DESIRED-NUMBER-OF-REPLICA&gt;
</code></pre>
<p><strong>short example:</strong></p>
<pre><code>kubectl scale deployment/deployment-web  --replicas=0
deployment.apps/deployment-web scaled
</code></pre>
<p><strong>Long Example</strong>:</p>
<p>// create a deployment called, <code>deployment-web</code> with two replicas.</p>
<pre><code>kubectl create  deployment  deployment-web --image=nginx --replicas 2
deployment.apps/deployment-web created
</code></pre>
<p>// verify that both replicas are up</p>
<pre><code>kubectl get deployments.apps 
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
deployment-web   2/2     2            2           13s
</code></pre>
<p>// expose the deployment with a service [OPTIONAL-STEP, ONLY FOR EXPLANATION]</p>
<pre><code>kubectl expose deployment deployment-web  --port 80
service/deployment-web exposed
</code></pre>
<p>//verify that the service is created</p>
<pre><code>kubectl get svc
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
deployment-web   ClusterIP   10.233.24.174   &lt;none&gt;        80/TCP    5s
</code></pre>
<p>// dump the list of end-points for that service, there would be one for each replica. Notice the two IPs in the 2nd column.</p>
<pre><code>kubectl get ep
NAME             ENDPOINTS                         AGE
deployment-web   10.233.111.6:80,10.233.115.9:80   12s
</code></pre>
<p>//scale down to 1 replica for the deployment</p>
<pre><code>kubectl scale --current-replicas=2 --replicas=1 deployment/deployment-web
deployment.apps/deployment-web scaled
</code></pre>
<p>// Notice the endpoint is reduced from 2 to 1.</p>
<pre><code>kubectl get ep
NAME             ENDPOINTS           AGE
deployment-web   10.233.115.9:80     43s
</code></pre>
<p>// also note that there is only one pod remaining</p>
<pre><code>kubectl get pod
NAME                             READY   STATUS    RESTARTS   AGE
deployment-web-64c769b44-qh2qf   1/1     Running   0          105s
</code></pre>
<p>// scale down to zero replica</p>
<pre><code>kubectl scale --current-replicas=1 --replicas=0 deployment/deployment-web
deployment.apps/deployment-web scaled
</code></pre>
<p>// The endpoint list is empty</p>
<pre><code>kubectl get ep
NAME             ENDPOINTS           AGE
deployment-web   &lt;none&gt;              9m4s
</code></pre>
<p>//Also, both pods are gone</p>
<pre><code>kubectl get pod 
No resources found in default namespace.
</code></pre>
<p>// When you are done with testing. restore the replicas</p>
<pre><code>kubectl scale --current-replicas=0 --replicas=2 deployment/deployment-web
deployment.apps/deployment-web scaled
</code></pre>
<p>//endpoints and pods are restored back</p>
<pre><code>kubectl get ep
NAME             ENDPOINTS                          AGE
deployment-web   10.233.111.8:80,10.233.115.11:80   10m
foo-svc          10.233.115.6:80                    50m
kubernetes       192.168.22.9:6443                  6d23h


kubectl get pod -l app=deployment-web
NAME                             READY   STATUS    RESTARTS   AGE
deployment-web-64c769b44-b72k5   1/1     Running   0          8s
deployment-web-64c769b44-mt2dd   1/1     Running   0          8s
</code></pre>
