## Introduction - 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" ![Node Restart](../../images/node-restart.png) ## Uses ??? info "View the uses of the experiment" coming soon ## Prerequisites ??? info "Verify the prerequisites" - Ensure that Kubernetes Version > 1.16 - Ensure that the Litmus Chaos Operator is running by executing kubectl get pods in operator namespace (typically, litmus).If not, install from here - Ensure that the node-restart experiment resource is available in the cluster by executing kubectl get chaosexperiments in the desired namespace. If not, install from here - 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: |- # SSH private key for ssh contained here ``` 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: 1. 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 ``` 2. 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 [documentation](https://www.ssh.com/ssh/keygen/). Once you have copied the public key to all nodes and created the secret described earlier, you are ready to start your experiment. ## Default Validations ??? info "View the default validations" The target nodes should be in ready state before and after chaos injection. ## Minimal RBAC configuration example (optional) !!! 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 [litmus-admin](https://litmuschaos.github.io/litmus/litmus-admin-rbac.yaml) RBAC, which is pre installed in the cluster as part of the agent setup. ??? note "View the Minimal RBAC permissions" [embedmd]:# (https://raw.githubusercontent.com/litmuschaos/chaos-charts/master/charts/generic/node-restart/rbac.yaml yaml) ```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","events","secrets"] verbs: ["create","list","get","patch","update","delete","deletecollection"] - apiGroups: [""] resources: ["pods/exec","pods/log"] verbs: ["create","list","get"] - apiGroups: ["batch"] resources: ["jobs"] verbs: ["create","list","get","delete","deletecollection"] - apiGroups: ["litmuschaos.io"] resources: ["chaosengines","chaosexperiments","chaosresults"] verbs: ["create","list","get","patch","update"] - 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) namespace. This example consists of the minimum necessary role permissions to execute the experiment. ## Experiment tunables ??? info "check the experiment tunables"

Mandatory Fields

Variables Description Notes
TARGET_NODE Name of target node, subjected to chaos. If not provided it will select the random node
NODE_LABEL It contains node label, which will be used to filter the target node if TARGET_NODE ENV is not set It is mutually exclusive with the TARGET_NODE ENV. If both are provided then it will use the TARGET_NODE

Optional Fields

Variables Description Notes
LIB_IMAGE The image used to restart the node Defaults to litmuschaos/go-runner:latest
SSH_USER name of ssh user Defaults to root
TARGET_NODE_IP Internal IP of the target node, subjected to chaos. If not provided, the experiment will lookup the node IP of the TARGET_NODE node Defaults to empty
REBOOT_COMMAND Command used for reboot Defaults to sudo systemctl reboot
TOTAL_CHAOS_DURATION The time duration for chaos insertion (sec) Defaults to 30s
RAMP_TIME Period to wait before and after injection of chaos in sec
LIB The chaos lib used to inject the chaos Defaults to litmus supported litmus only
## Experiment Examples ### Common and Node specific tunables Refer the [common attributes](../common/common-tunables-for-all-experiments.md) and [Node specific tunable](common-tunables-for-node-experiments.md) to tune the common tunables for all experiments and node specific tunables. ### Reboot Command 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: [embedmd]:# (https://raw.githubusercontent.com/litmuschaos/litmus/master/mkdocs/docs/experiments/categories/nodes/node-restart/reboot-command.yaml yaml) ```yaml # provide the reboot command 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: # command used for the reboot - name: REBOOT_COMMAND value: 'sudo systemctl reboot' # name of the target node - name: TARGET_NODE value: 'node01' - name: TOTAL_CHAOS_DURATION VALUE: '60' ``` ### SSH User 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: [embedmd]:# (https://raw.githubusercontent.com/litmuschaos/litmus/master/mkdocs/docs/experiments/categories/nodes/node-restart/ssh-user.yaml yaml) ```yaml # name of the ssh user used to ssh into targeted node 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 of the ssh user - name: SSH_USER value: 'root' # name of the target node - name: TARGET_NODE value: 'node01' - name: TOTAL_CHAOS_DURATION VALUE: '60' ``` ### Target Node Internal IP 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 `TARGET_NODE_IP` ENV. Use the following example to tune this: [embedmd]:# (https://raw.githubusercontent.com/litmuschaos/litmus/master/mkdocs/docs/experiments/categories/nodes/node-restart/target-node-ip.yaml yaml) ```yaml # internal ip of the targeted node 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: # internal ip of the targeted node - name: TARGET_NODE_IP value: '' # name of the target node - name: TARGET_NODE value: 'node01' - name: TOTAL_CHAOS_DURATION VALUE: '60' ```