本文提供從命令行 (CLI) 建立實驗的範例,以及各種實驗的 Azure 入口網站 參數範例。 您可以將下列命令複製並貼到 CLI 或 Azure 入口網站,並針對您的特定資源加以編輯。
以下是您將複製並貼上 Azure 入口網站 參數的範例:
若要儲存以下所示的其中一個「experiment.json」範例,只要在 Cloud Shell 中輸入 nano experiment.json ,複製並貼上下列任何實驗範例、儲存它 (ctrl+o)、結束 nano (ctrl+x),然後執行下列命令:
az rest --method put --uri https://management.azure.com/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/exampleRG/providers/Microsoft.Chaos/experiments/exampleExperiment?api-version=2024-01-01
注意
這是您用來從 Azure CLI 建立任何實驗的一般命令
注意
請確定您的實驗有權在實驗內的所有資源上操作。 這些範例僅使用 系統指派的受控識別,但我們也支援使用者指派的受控識別。 如需詳細資訊,請參閱 實驗許可權。 這些實驗不會在授與在目標資源上執行的實驗許可權的情況下執行。
在此檢視所有可用的角色指派,以判斷目標資源所需的許可權。
Azure Kubernetes Service (AKS) - 網络延遲
實驗描述 此實驗會延遲 200 毫秒的網路通訊
{
"identity": {
"type": "SystemAssigned",
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_network_delay_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS network latency",
"branches": [
{
"name": "AKS network latency",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"delay\",\"mode\":\"all\",\"selector\":{\"namespaces\":[\"default\"]},\"delay\":{\"latency\":\"200ms\",\"correlation\":\"100\",\"jitter\":\"0ms\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:networkChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - Pod 失敗
實驗描述 此實驗會關閉叢集中的所有 Pod 10 分鐘。
{
"identity": {
"type": "SystemAssigned",
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_pod_fail_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS pod kill",
"branches": [
{
"name": "AKS pod kill",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"pod-failure\",\"mode\":\"all\",\"duration\":\"600s\",\"selector\":{\"namespaces\":[\"autoinstrumentationdemo\"]}}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:podChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - 記憶體壓力
實驗描述 此實驗會將 4 個 AKS Pod 的記憶體強調為 10 分鐘 95%。
{
"identity": {
"type": "SystemAssigned",
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_memory_stress_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS memory stress",
"branches": [
{
"name": "AKS memory stress",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT10M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"mode\":\"all\",\"selector\":{\"namespaces\":[\"autoinstrumentationdemo\"]},\"stressors\":{\"memory\":{\"workers\":4,\"size\":\"95%\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:stressChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - CPU 壓力
實驗描述 此實驗會將 AKS 叢集中四個 Pod 的 CPU 強調為 95%。
{
"identity": {
"type": "SystemAssigned"
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_memory_stress_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS CPU stress",
"branches": [
{
"name": "AKS CPU stress",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT10M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"mode\":\"all\",\"selector\":{\"namespaces\":[\"autoinstrumentationdemo\"]},\"stressors\":{\"cpu\":{\"workers\":4,\"load\":95}}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:stressChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - 網络模擬
實驗描述 此實驗會將網路模擬套用至指定命名空間中的所有 Pod,並在 5 分鐘內新增 100 毫秒的延遲和封包遺失 0.1%。
{
"identity": {
"type": "SystemAssigned"
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_network_emulation_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS network emulation",
"branches": [
{
"name": "AKS network emulation",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"netem\",\"mode\":\"all\",\"selector\":{\"namespaces\":[\"default\"]},\"netem\":{\"latency\":\"100ms\",\"loss\":\"0.1\",\"correlation\":\"25\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:networkChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - 網络分割
實驗描述 此實驗會分割指定命名空間中所有 Pod 的網路,並在「到」方向中模擬網路分割 5 分鐘。
{
"identity": {
"type": "SystemAssigned"
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_partition_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS network partition",
"branches": [
{
"name": "AKS network partition",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"partition\",\"mode\":\"all\",\"selector\":{\"namespaces\":[\"default\"]},\"partition\":{\"direction\":\"to\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:networkChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - 網络带寬限制
實驗描述 此實驗會將指定命名空間中所有 Pod 的網路頻寬限制為 1mbps,並將限制、緩衝區、尖峰速率和高載的額外參數限制為 5 分鐘。
{
"identity": {
"type": "SystemAssigned"
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_bandwidth_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS network bandwidth",
"branches": [
{
"name": "AKS network bandwidth",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"bandwidth\",\"mode\":\"all\",\"selector\":{\"namespaces\":[\"default\"]},\"bandwidth\":{\"rate\":\"1mbps\",\"limit\":\"50mb\",\"buffer\":\"10kb\",\"peakrate\":\"1mbps\",\"minburst\":\"0\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:networkChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - 網络封包重新排序
實驗描述 此實驗會重新排列指定命名空間中所有 Pod 的網路封包,差距為 5 個封包,5 分鐘重新排序百分比為 25%。
{
"identity": {
"type": "SystemAssigned"
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_reorder_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS network reorder",
"branches": [
{
"name": "AKS network reorder",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"reorder\",\"mode\":\"all\",\"selector\":{\"namespaces\":[\"default\"]},\"reorder\":{\"gap\":\"5\",\"reorder\":\"25\",\"correlation\":\"50\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:networkChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - 網络封包遺失
實驗描述 此實驗會針對指定命名空間中的所有 Pod 模擬 5 分鐘封包遺失 10%。
{
"identity": {
"type": "SystemAssigned"
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_loss_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS network loss",
"branches": [
{
"name": "AKS network loss",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"loss\",\"mode\":\"all\",\"selector\":{\"namespaces\":[\"default\"]},\"loss\":{\"loss\":\"10\",\"correlation\":\"25\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:networkChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - 網络封包重複
實驗描述 此實驗會複製指定命名空間中所有 Pod 50% 的網路封包 50%。
{
"identity": {
"type": "SystemAssigned"
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_duplicate_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS network duplicate",
"branches": [
{
"name": "AKS network duplicate",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"duplicate\",\"mode\":\"all\",\"selector\":{\"namespaces\":[\"default\"]},\"duplicate\":{\"duplicate\":\"50\",\"correlation\":\"50\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:networkChaos/2.2"
}
]
}
]
}
]
}
}
Azure Kubernetes Service (AKS) - 網络封包損毀
實驗描述 此實驗會損毀指定命名空間中所有 Pod 50% 的網路封包 50%。
{
"identity": {
"type": "SystemAssigned"
},
"tags": {},
"location": "westus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/aks_corrupt_experiment/providers/Microsoft.ContainerService/managedClusters/nikhilAKScluster/providers/Microsoft.Chaos/targets/Microsoft-AzureKubernetesServiceChaosMesh",
"type": "ChaosTarget"
}
],
"id": "Selector1"
}
],
"steps": [
{
"name": "AKS network corrupt",
"branches": [
{
"name": "AKS network corrupt",
"actions": [
{
"type": "continuous",
"selectorId": "Selector1",
"duration": "PT5M",
"parameters": [
{
"key": "jsonSpec",
"value": "{\"action\":\"corrupt\",\"mode\":\"all\",\"selector\":{\"namespaces\":[\"default\"]},\"corrupt\":{\"corrupt\":\"50\",\"correlation\":\"50\"}}"
}
],
"name": "urn:csci:microsoft:azureKubernetesServiceChaosMesh:networkChaos/2.2"
}
]
}
]
}
]
}
}
Azure 負載測試 - 啟動/停止負載測試(延遲)
實驗描述 此實驗會啟動現有的 Azure 負載測試,然後在停止負載測試之前,先使用「延遲」動作等候 10 分鐘。
{
"identity": {
"type": "SystemAssigned",
},
"tags": {},
"location": "eastus",
"properties": {
"selectors": [
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/nikhilLoadTest/providers/microsoft.loadtestservice/loadtests/Nikhil-Demo-Load-Test/providers/Microsoft.Chaos/targets/microsoft-azureloadtest",
"type": "ChaosTarget"
}
],
"id": "66e5124c-12db-4f7e-8549-7299c5828bff"
},
{
"type": "List",
"targets": [
{
"id": "/subscriptions/123hdq8-123d-89d7-5670-123123/resourceGroups/builddemo/providers/microsoft.loadtestservice/loadtests/Nikhil-Demo-Load-Test/providers/Microsoft.Chaos/targets/microsoft-azureloadtest",
"type": "ChaosTarget"
}
],
"id": "9dc23b43-81ca-42c3-beae-3fe8ac80c30b"
}
],
"steps": [
{
"name": "Step 1 - Start Load Test",
"branches": [
{
"name": "Branch 1",
"actions": [
{
"selectorId": "66e5124c-12db-4f7e-8549-7299c5828bff",
"type": "discrete",
"parameters": [
{
"key": "testId",
"value": "ae24e6z9-d88d-4752-8552-c73e8a9adebc"
}
],
"name": "urn:csci:microsoft:azureLoadTest:start/1.0"
},
{
"type": "delay",
"duration": "PT10M",
"name": "urn:csci:microsoft:chaosStudio:TimedDelay/1.0"
}
]
}
]
},
{
"name": "Step 2 - End Load test",
"branches": [
{
"name": "Branch 1",
"actions": [
{
"selectorId": "9dc23b43-81ca-42c3-beae-3fe8ac80c30b",
"type": "discrete",
"parameters": [
{
"key": "testId",
"value": "ae24e6z9-d88d-4752-8552-c73e8a9adebc"
}
],
"name": "urn:csci:microsoft:azureLoadTest:stop/1.0"
}
]
}
]
}
]
}
}
}