Skip to content

Commit 14c2a90

Browse files
blanquicetmbifeld
authored andcommitted
scenarios: Add Inspektor Gadget on AKS use case
Signed-off-by: Jose Blanquicet <[email protected]>
1 parent 50b2042 commit 14c2a90

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Quickstart: Deploy Inspektor Gadget in an Azure Kubernetes Service cluster
2+
3+
Welcome to this tutorial where we will take you step by step in deploying [Inspektor Gadget](https://www.inspektor-gadget.io/) in an Azure Kubernetes Service (AKS) cluster with the kubectl plugin: `gadget`. This tutorial assumes you are logged into Azure CLI already and have selected a subscription to use with the CLI.
4+
5+
## Define Environment Variables
6+
7+
The First step in this tutorial is to define environment variables:
8+
9+
```bash
10+
export RANDOM_ID="$(openssl rand -hex 3)"
11+
export MY_RESOURCE_GROUP_NAME="myResourceGroup$RANDOM_ID"
12+
export REGION="eastus"
13+
export MY_AKS_CLUSTER_NAME="myAKSCluster$RANDOM_ID"
14+
```
15+
16+
## Create a resource group
17+
18+
A resource group is a container for related resources. All resources must be placed in a resource group. We will create one for this tutorial. The following command creates a resource group with the previously defined $MY_RESOURCE_GROUP_NAME and $REGION parameters.
19+
20+
```bash
21+
az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION
22+
```
23+
24+
Results:
25+
26+
<!-- expected_similarity=0.3 -->
27+
```JSON
28+
{
29+
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup210",
30+
"location": "eastus",
31+
"managedBy": null,
32+
"name": "testResourceGroup",
33+
"properties": {
34+
"provisioningState": "Succeeded"
35+
},
36+
"tags": null,
37+
"type": "Microsoft.Resources/resourceGroups"
38+
}
39+
```
40+
41+
## Create AKS Cluster
42+
43+
Create an AKS cluster using the az aks create command.
44+
45+
This will take a few minutes.
46+
47+
```bash
48+
az aks create \
49+
--resource-group $MY_RESOURCE_GROUP_NAME \
50+
--name $MY_AKS_CLUSTER_NAME \
51+
--location $REGION \
52+
--no-ssh-key
53+
```
54+
55+
## Connect to the cluster
56+
57+
To manage a Kubernetes cluster, use the Kubernetes command-line client, kubectl. kubectl is already installed if you use Azure Cloud Shell.
58+
59+
1. Install az aks CLI locally using the az aks install-cli command
60+
61+
```bash
62+
if ! [ -x "$(command -v kubectl)" ]; then az aks install-cli; fi
63+
```
64+
65+
2. Configure kubectl to connect to your Kubernetes cluster using the az aks get-credentials command. The following command:
66+
- Downloads credentials and configures the Kubernetes CLI to use them.
67+
- Uses ~/.kube/config, the default location for the Kubernetes configuration file. Specify a different location for your Kubernetes configuration file using --file argument.
68+
69+
> [!WARNING]
70+
> This will overwrite any existing credentials with the same entry
71+
72+
```bash
73+
az aks get-credentials --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_AKS_CLUSTER_NAME --overwrite-existing
74+
```
75+
76+
3. Verify the connection to your cluster using the kubectl get command. This command returns a list of the cluster nodes.
77+
78+
```bash
79+
kubectl get nodes
80+
```
81+
82+
## Install Inspektor Gadget
83+
84+
The Inspektor Gadget installation is composed of two steps:
85+
86+
1. Installing the kubectl plugin in the user's system.
87+
2. Installing Inspektor Gadget in the cluster.
88+
89+
> [!NOTE]
90+
> There are additional mechanisms for deploying and utilizing Inspektor Gadget, each tailored to specific use cases and requirements. Using the `kubectl gadget` plugin covers many of them, but not all. For instance, deploying Inspektor Gadget with the `kubectl gadget` plugin depends on the Kubernetes API server's availability. So, if you can’t depend on such a component because its availability could be sometimes compromised, then it is recommended to not use the `kubectl gadget`deployment mechanism. Please check [ig documentation](https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/ig.md) to know what to do in that, and other use cases.
91+
92+
### Installing the kubectl plugin: `gadget`
93+
94+
Install the latest version of the kubectl plugin from the releases page, uncompress and move the `kubectl-gadget` executable to `$HOME/.local/bin`:
95+
96+
> [!NOTE]
97+
> If you want to install it using [`krew`](https://sigs.k8s.io/krew) or compile it from the source, please follow the official documentation: [installing kubectl gadget](https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/install.md#installing-kubectl-gadget).
98+
99+
```bash
100+
IG_VERSION=$(curl -s https://api.github.com/repos/inspektor-gadget/inspektor-gadget/releases/latest | jq -r .tag_name)
101+
IG_ARCH=amd64
102+
mkdir -p $HOME/.local/bin
103+
export PATH=$PATH:$HOME/.local/bin
104+
curl -sL https://github.com/inspektor-gadget/inspektor-gadget/releases/download/${IG_VERSION}/kubectl-gadget-linux-${IG_ARCH}-${IG_VERSION}.tar.gz | tar -C $HOME/.local/bin -xzf - kubectl-gadget
105+
```
106+
107+
Now, let’s verify the installation by running the `version` command:
108+
109+
```bash
110+
kubectl gadget version
111+
```
112+
113+
The `version` command will display the version of the client (kubectl gadget plugin) and show that it is not yet installed in the server (the cluster):
114+
115+
<!--expected_similarity="(?m)^Client version: v\d+\.\d+\.\d+$\n^Server version: not installed$"-->
116+
```text
117+
Client version: vX.Y.Z
118+
Server version: not installed
119+
```
120+
121+
### Installing Inspektor Gadget in the cluster
122+
123+
The following command will deploy the DaemonSet:
124+
125+
> [!NOTE]
126+
> Several options are available to customize the deployment: use a specific container image, deploy to specific nodes, and many others. To know all of them, please check the official documentation: [installing in the cluster](https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/install.md#installing-in-the-cluster).
127+
128+
```bash
129+
kubectl gadget deploy
130+
```
131+
132+
Now, let’s verify the installation by running the `version` command again:
133+
134+
```bash
135+
kubectl gadget version
136+
```
137+
138+
This time, the client and server will be correctly installed:
139+
140+
<!--expected_similarity="(?m)^Client version: v\d+\.\d+\.\d+$\n^Server version: v\d+\.\d+\.\d+$"-->
141+
```text
142+
Client version: vX.Y.Z
143+
Server version: vX.Y.Z
144+
```
145+
146+
You can now start running the gadgets:
147+
148+
```bash
149+
kubectl gadget help
150+
```
151+
152+
<!--
153+
## Clean Up
154+
155+
### Undeploy Inspektor Gadget
156+
157+
```bash
158+
kubectl gadget undeploy
159+
```
160+
161+
### Clean up Azure resources
162+
163+
When no longer needed, you can use `az group delete` to remove the resource group, cluster, and all related resources as follows. The `--no-wait` parameter returns control to the prompt without waiting for the operation to complete. The `--yes` parameter confirms that you wish to delete the resources without an additional prompt to do so.
164+
165+
```bash
166+
az group delete --name $MY_RESOURCE_GROUP_NAME --no-wait --yes
167+
```
168+
-->

0 commit comments

Comments
 (0)