Project: Litmus (Observability and Analysis / Chaos Engineering)
File: node-restart.md

It causes chaos to disrupt state of node by restarting it. It tests deployment sanity (replica availability & uninterrupted service) and recovery workflows of the application pod !!! tip "Scenario: Restart the node" ??? info "View the uses of the experiment" coming soon ??? info "Verify the prerequisites" Ensure that Kubernetes Version > 1.16 Ensure that the Litmus Chaos Operator is running by executing <code>kubectl get pods</code> in operator namespace (typically, <code>litmus</code>).If not, install from <a href="https://v1-docs.litmuschaos.io/docs/getstarted/#install-litmus">here</a> Ensure that the <code>node-restart</code> experiment resource is available in the cluster by executing <code>kubectl get chaosexperiments</code> in the desired namespace. If not, install from <a href="https://hub.litmuschaos.io/api/chaos/master?file=faults/kubernetes/node-restart/fault.yaml">here</a> Create a Kubernetes secret named `id-rsa` where the experiment will run, where its contents will be the private SSH key for `SSH_USER` used to connect to the node that hosts the target pod in the secret field `ssh-privatekey`. A sample secret is shown below: ```yaml apiVersion: v1 kind: Secret metadata: name: id-rsa type: kubernetes.io/ssh-auth stringData: ssh-privatekey: |- ``` Creating the RSA key pair for remote SSH access should be a trivial exercise for those who are already familiar with an ssh client, which entails the following actions: Create a new key pair and store the keys in a file named `my-id-rsa-key` and `my-id-rsa-key.pub` for the private and public keys respectively: ``` ssh-keygen -f ~/my-id-rsa-key -t rsa -b 4096 ``` For each node available, run this following command to copy the public key of `my-id-rsa-key`: ``` ssh-copy-id -i my-id-rsa-key user@node ``` For further details, please check this . Once you have copied the public key to all nodes and created the secret described earlier, you are ready to start your experiment. ??? info "View the default validations" The target nodes should be in ready state before and after chaos injection. !!! tip "NOTE" If you are using this experiment as part of a litmus workflow scheduled constructed & executed from chaos-center, then you may be making use of the RBAC, which is pre installed in the cluster as part of the agent setup. ??? note "View the Minimal RBAC permissions" ```yaml apiVersion: v1 kind: ServiceAccount metadata: name: node-restart-sa namespace: default labels: name: node-restart-sa app.kubernetes.io/part-of: litmus apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: node-restart-sa labels: name: node-restart-sa app.kubernetes.io/part-of: litmus rules: apiGroups: [""] resources: ["pods"] verbs: ["create","delete","get","list","patch","update", "deletecollection"] apiGroups: [""] resources: ["events"] verbs: ["create","get","list","patch","update"] apiGroups: [""] resources: ["configmaps","secrets"] verbs: ["get","list",] apiGroups: [""] resources: ["pods/log"] verbs: ["get","list","watch"] apiGroups: [""] resources: ["pods/exec"] verbs: ["get","list","create"] apiGroups: ["batch"] resources: ["jobs"] verbs: ["create","list","get","delete","deletecollection"] apiGroups: ["litmuschaos.io"] resources: ["chaosengines","chaosexperiments","chaosresults"] verbs: ["create","list","get","patch","update","delete"] apiGroups: [""] resources: ["nodes"] verbs: ["get","list"] apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: node-restart-sa labels: name: node-restart-sa app.kubernetes.io/part-of: litmus roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: node-restart-sa subjects: kind: ServiceAccount name: node-restart-sa namespace: default ``` Use this sample RBAC manifest to create a chaosServiceAccount in the desired (app)

This example consists of the minimum necessary role permissions to execute the experiment. ??? info "check the experiment tunables" <h2>Mandatory Fields</h2> <table> <tr> <th> Variables </th> <th> Description </th> <th> Notes </th> </tr> <tr> <td> TARGET_NODE </td> <td> Name of target node, subjected to chaos. If not provided it will select the random node</td> <td> </td> </tr> <tr> <td> NODE_LABEL </td> <td> It contains node label, which will be used to filter the target node if TARGET_NODE ENV is not set </td> <td>It is mutually exclusive with the TARGETNODE ENV. If both are provided then it will use the TARGETNODE</td> </tr> </table> <h2>Optional Fields</h2> <table> <tr> <th> Variables </th> <th> Description </th> <th> Notes </th> </tr> <tr> <td> LIB_IMAGE </td> <td> The image used to restart the node </td> <td> Defaults to <code>litmuschaos/go-runner:latest</code> </td> </tr> <tr> <td> SSH_USER </td> <td> name of ssh user </td> <td> Defaults to <code>root</code> </td> </tr> <tr> <td> TARGETNODEIP </td> <td> Internal IP of the target node, subjected to chaos. If not provided, the experiment will lookup the node IP of the <code>TARGET_NODE</code> node</td> <td> Defaults to empty </td> </tr> <tr> <td> REBOOT_COMMAND </td> <td> Command used for reboot </td> <td> Defaults to <code>sudo systemctl reboot</code> </td> </tr> <tr> <td> TOTALCHAOSDURATION </td> <td> The time duration for chaos insertion (sec) </td> <td> Defaults to 30s </td> </tr> <tr> <td> RAMP_TIME </td> <td> Period to wait before and after injection of chaos in sec </td> <td> </td> </tr> <tr> <td> LIB </td> <td> The chaos lib used to inject the chaos </td> <td> Defaults to </code>litmus</code> supported litmus only </td> </tr> </table> Refer the and to tune the common tunables for all experiments and node specific tunables. It defines the command used to restart the targeted node. It can be tuned via `REBOOT_COMMAND` ENV. Use the following example to tune this: ```yaml apiVersion: litmuschaos.io/v1alpha1 kind: ChaosEngine metadata: name: engine-nginx spec: engineState: "active" annotationCheck: "false" chaosServiceAccount: node-restart-sa experiments: name: node-restart spec: components: env: name: REBOOT_COMMAND value: 'sudo systemctl reboot' name: TARGET_NODE value: 'node01' name: TOTALCHAOSDURATION value: '60' ``` It defines the name of the SSH user for the targeted node. It can be tuned via `SSH_USER` ENV. Use the following example to tune this: ```yaml apiVersion: litmuschaos.io/v1alpha1 kind: ChaosEngine metadata: name: engine-nginx spec: engineState: "active" annotationCheck: "false" chaosServiceAccount: node-restart-sa experiments: name: node-restart spec: components: env: name: SSH_USER value: 'root' name: TARGET_NODE value: 'node01' name: TOTALCHAOSDURATION value: '60' ``` It defines the internal IP of the targeted node. It is an optional field, if internal IP is not provided then it will derive the internal IP of the targeted node. It can be tuned via `TARGETNODEIP` ENV. Use the following example to tune this: ```yaml apiVersion: litmuschaos.io/v1alpha1 kind: ChaosEngine metadata: name: engine-nginx spec: engineState: "active" annotationCheck: "false" chaosServiceAccount: node-restart-sa experiments: name: node-restart spec: components: env: name: TARGETNODEIP value: '<ip of node01>' name: TARGET_NODE value: 'node01' name: TOTALCHAOSDURATION value: '60' ```