I have a kubernetes cluster with node pools and as a part of Chaos Engineering Initiative,I need to restart the VM. Is there any code for the same using azure resource graph?
3 Answers
When the AKS nodes is a scale set. Then you need to find the node resource group, the scale set name, and the instance-id that you want to restart. And then restart the instance. Here are the CLI commands:
# get the AKS node resource group name
az aks show -g groupName -n aksName --query nodeResourceGroup
# get the scale set info and all the instance id
az vmss list -g nodeGroupName --query [].name
az vmss list-instances -g nodeGroupName -n vmssName -o table
# restart the instance with the instance Id
az vmss restart -g nodeGroupName -n vmssName --instance-ids n
If you do it in the Azure portal, the same steps but it's easier to achieve.

- 29,862
- 2
- 22
- 39
-
how do it using az graph query? – Batman22 Nov 05 '20 at 17:46
-
@Batman22 I'm afraid not. The command `az graph query` only can get the scale set, cannot get the instance Id for you. – Charles Xu Nov 06 '20 at 07:38
-
We did it using instance id...I will post the answer soon. thank! – Batman22 Nov 06 '20 at 16:54
-
@Batman22 Why you will post an answer? My answer does not solve your problem? If it solves your issue, what you need to do is accept it. – Charles Xu Nov 09 '20 at 01:34
-
@Batman22 What's the reason you do not accept the answer when it helps you solve the problem? It's not difficult to do it! – Charles Xu Nov 10 '20 at 08:00
-
the answer is different i will post it soon. thanks! – Batman22 Nov 10 '20 at 08:14
-
I upvoted it but will post a python code for doing the same since i asked specifically for the way to do it with code – Batman22 Nov 13 '20 at 20:01
-
@Batman22 Where do you say you need to do it in python in the question? No one will guess what you need if you do not elaborate on it clearly. – Charles Xu Nov 16 '20 at 01:29
You can install Gremlin on your AKS cluster. Here is an in-depth tutorial that I wrote: https://www.gremlin.com/community/tutorials/how-to-install-and-use-gremlin-with-kubernetes/
When practicing Chaos Engineering on a kubernetes cluster it's important to control the blast radius of your attacks - e.g. how many VMs will you restart? Do you want to restart the whole VM or just 1 or more pods on the VM.

- 51
- 2
Chaos toolkit already has the code for fetching vms from scaleset. The code can be checked at https://github.com/chaostoolkit-incubator/chaostoolkit-azure/blob/master/chaosazure/vmss/fetcher.py.

- 376
- 4
- 25