github.com/inspektor-gadget/inspektor-gadget@v0.28.1/docs/getting-started/install-kubernetes.md (about) 1 --- 2 title: Installing on Kubernetes 3 weight: 10 4 description: > 5 How to install Inspektor Gadget on Kubernetes 6 --- 7 8 <!-- toc --> 9 - [Installing kubectl gadget](#installing-kubectl-gadget) 10 - [Using krew](#using-krew) 11 - [Install a specific release](#install-a-specific-release) 12 - [Compile from source](#compile-from-source) 13 - [Installing in the cluster](#installing-in-the-cluster) 14 - [Quick installation](#quick-installation) 15 - [Choosing the gadget image](#choosing-the-gadget-image) 16 - [Deploy to specific nodes](#deploy-to-specific-nodes) 17 - [Deploying into a custom namespace](#deploying-into-a-custom-namespace) 18 - [Hook Mode](#hook-mode) 19 - [Deploying with an AppArmor profile](#deploying-with-an-apparmor-profile) 20 - [Specific Information for Different Platforms](#specific-information-for-different-platforms) 21 - [Minikube](#minikube) 22 - [Uninstalling from the cluster](#uninstalling-from-the-cluster) 23 - [Version skew policy](#version-skew-policy) 24 - [Installing `ig`](#installing-ig) 25 - [Install a specific release](#install-a-specific-release-1) 26 - [Compile from source](#compile-from-source-1) 27 - [Experimental features](#experimental-features) 28 <!-- /toc --> 29 30 Inspektor Gadget is composed of a `kubectl` plugin executed in the user's 31 system and a DaemonSet deployed in the cluster. 32 33 ## Installing kubectl gadget 34 35 Choose one way to install the Inspektor Gadget `kubectl` plugin. 36 37 ### Using krew 38 39 [krew](https://sigs.k8s.io/krew) is the recommended way to install 40 `kubectl gadget`. You can follow the 41 [krew's quickstart](https://krew.sigs.k8s.io/docs/user-guide/quickstart/) 42 to install it and then install `kubectl gadget` by executing the following 43 commands. 44 45 ```bash 46 $ kubectl krew install gadget 47 $ kubectl gadget --help 48 ``` 49 50 ### Install a specific release 51 52 Download the asset for a given release and platform from the 53 [releases page](https://github.com/inspektor-gadget/inspektor-gadget/releases/), 54 uncompress and move the `kubectl-gadget` executable to your `PATH`. 55 56 ```bash 57 $ IG_VERSION=$(curl -s https://api.github.com/repos/inspektor-gadget/inspektor-gadget/releases/latest | jq -r .tag_name) 58 $ IG_ARCH=amd64 59 $ curl -sL https://github.com/inspektor-gadget/inspektor-gadget/releases/download/${IG_VERSION}/kubectl-gadget-linux-${IG_ARCH}-${IG_VERSION}.tar.gz | sudo tar -C /usr/local/bin -xzf - kubectl-gadget 60 $ kubectl gadget version 61 ``` 62 63 ### Compile from source 64 65 To build Inspektor Gadget from source, you'll need to have a Golang version 66 1.22 or higher installed. 67 68 ```bash 69 $ git clone https://github.com/inspektor-gadget/inspektor-gadget.git 70 $ cd inspektor-gadget 71 $ make kubectl-gadget-linux-amd64 72 $ sudo cp kubectl-gadget-linux-amd64 /usr/local/bin/kubectl-gadget 73 $ kubectl gadget version 74 ``` 75 76 ## Installing in the cluster 77 78 ### Quick installation 79 80 ```bash 81 $ kubectl gadget deploy 82 ``` 83 84 This will deploy the gadget DaemonSet along with its RBAC rules. 85 86  87 88 ### Choosing the gadget image 89 90 If you wish to install an alternative gadget image, you could use the following commands: 91 92 ```bash 93 $ kubectl gadget deploy --image=ghcr.io/myfork/inspektor-gadget:tag 94 ``` 95 96 ### Deploy to specific nodes 97 98 The `--node-selector` flag accepts a [label 99 selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors) 100 that defines the nodes where Inspektor Gadget will be deloyed to: 101 102 ```bash 103 # Deploy only to the minikube-m02 node 104 $ kubectl gadget deploy --node-selector kubernetes.io/hostname=minikube-m02 105 106 # Deploy to all nodes but minikube 107 $ kubectl gadget deploy --node-selector kubernetes.io/hostname!=minikube 108 109 # Deploy to minikube and minikube-m03 nodes only 110 $ kubectl gadget deploy --node-selector 'kubernetes.io/hostname in (minikube, minikube-m03)' 111 ``` 112 113 ### Deploying into a custom namespace 114 115 By default Inspektor Gadget is deployed to the namespace `gadget`. 116 This can be changed with the `--gadget-namespace` flag. 117 When using gadgets (e.g. `kubectl gadget trace exec`) the deployed namespace is discovered automatically and no additional flags are needed during the usage. 118 For `undeploy` the `--gadget-namespace` flag is mandatory. 119 120 ### Hook Mode 121 122 Inspektor Gadget needs to detect when containers are started and stopped. 123 The different supported modes can be set by using the `hook-mode` option: 124 125 - `auto`(default): Inspektor Gadget will try to find the best option based on 126 the system it is running on. 127 - `crio`: Use the [CRIO 128 hooks](https://github.com/containers/podman/blob/v3.4.4/pkg/hooks/docs/oci-hooks.5.md) 129 support. Inspektor Gadget installs the required hooks in 130 `/etc/containers/oci/hooks.d`, be sure that path is part of the `hooks_dir` 131 option on 132 [crio.conf](https://github.com/cri-o/cri-o/blob/v1.20.0/docs/crio.conf.5.md#crioruntime-table). 133 If `hooks_dir` is not declared at all, that path is considered by default. 134 - `podinformer`: Use a Kubernetes controller to get information about new pods. 135 This option is racy and the first events produced by a container could be 136 lost. This mode is selected when `auto` is used and the above modes are not 137 available. 138 - `nri`: Use the [Node Resource Interface](https://github.com/containerd/nri). 139 It requires containerd v1.5 and it's not considered when `auto` is used. 140 - `fanotify`: Uses the Linux 141 [fanotify](https://man7.org/linux/man-pages/man7/fanotify.7.html) API. It 142 works with both runc and crun. It requires to run in the host pid namespace 143 (`hostPID=true`). 144 - `fanotify+ebpf`: Uses the Linux 145 [fanotify](https://man7.org/linux/man-pages/man7/fanotify.7.html) API and an 146 eBPF module. It works with both runc and crun. It works regardless of the 147 pid namespace configuration. 148 149 ### Deploying with an AppArmor profile 150 151 By default, Inspektor Gadget runs as unconfined because it needs to write to different files under `/sys`. 152 It is nonetheless possible to deploy Inspektor Gadget using a custom AppArmor profile with the `--apparmor-profile` flag: 153 154 ```bash 155 $ kubectl gadget deploy --apparmor-profile 'localhost/inspektor-gadget-profile' 156 ``` 157 158 Note that, the AppArmor profile should already exists in the cluster to be used. 159 160 ### Deploying with a seccomp profile 161 162 By default, Inspektor Gadget syscalls are not restricted. 163 If the seccomp profile operator is [installed](https://github.com/kubernetes-sigs/security-profiles-operator/blob/main/installation-usage.md#install-operator), you can use the `--seccomp-profile` flag to deploy Inspektor Gadget with a custom seccomp profile. 164 Note that, the profile should follow the [`SeccompProfile` format](https://github.com/kubernetes-sigs/security-profiles-operator/blob/main/installation-usage.md#create-a-seccomp-profile): 165 166 ```bash 167 $ cat 'gadget-profile.yaml' 168 apiVersion: security-profiles-operator.x-k8s.io/v1beta1 169 kind: SeccompProfile 170 metadata: 171 namespace: gadget 172 name: profile 173 spec: 174 defaultAction: SCMP_ACT_ERRNO 175 syscalls: 176 - action: SCMP_ACT_ALLOW 177 names: 178 - accept4 179 - access 180 - arch_prctl 181 - bind 182 ... 183 $ kubectl gadget deploy --seccomp-profile 'gadget-profile.yaml' 184 ``` 185 186 ### Specific Information for Different Platforms 187 188 This section explains the additional steps that are required to run Inspektor 189 Gadget in some platforms. 190 191 #### Minikube 192 193 You can deploy Inspektor Gadget in `minikube` in different ways: 194 - Manually, using the `kubectl gadget deploy` command as described above. 195 - Using the [Inspektor Gadget Addon](https://minikube.sigs.k8s.io/docs/handbook/addons/inspektor-gadget/) available 196 since [minikube v1.31.0](https://github.com/kubernetes/minikube/releases). 197 198 We recommend to use the `docker` driver: 199 200 ```bash 201 $ minikube start --driver=docker 202 # Deploy Inspektor Gadget in the cluster as described above 203 ``` 204 205 But can also use the `kvm2` one: 206 207 ```bash 208 $ minikube start --driver=kvm2 209 # Deploy Inspektor Gadget in the cluster as described above 210 ``` 211 212 ## Uninstalling from the cluster 213 214 The following command will remove all the resources created by Inspektor 215 Gadget from the cluster: 216 217 ```bash 218 $ kubectl gadget undeploy 219 ``` 220 221 ## Version skew policy 222 223 Inspektor Gadget requires the kubectl-gadget plugin and the DaemonSet 224 deployed on the cluster to be the exact same version. Even if this is 225 possible that different versions work well together, we don't provide 226 any guarantee in those cases. We'll visit this policy again once we 227 approach to the v1.0 release. 228 229 ## Installing `ig` 230 231 The [`ig`](../ig.md) tool can be built and installed 232 independently. The result is a single binary (statically linked) that can be 233 copied to a Kubernetes node or any host to trace its containers. 234 235 ### Install a specific release 236 237 It is possible to download the asset for a given release and platform from the 238 [releases page](https://github.com/inspektor-gadget/inspektor-gadget/releases/). 239 240 For instance, to download the latest release for linux-amd64: 241 242 ```bash 243 $ IG_VERSION=$(curl -s https://api.github.com/repos/inspektor-gadget/inspektor-gadget/releases/latest | jq -r .tag_name) 244 $ IG_ARCH=amd64 245 $ curl -sL https://github.com/inspektor-gadget/inspektor-gadget/releases/download/${IG_VERSION}/ig-linux-${IG_ARCH}-${IG_VERSION}.tar.gz | sudo tar -C /usr/local/bin -xzf - ig 246 $ ig version 247 ``` 248 249 ### Compile from source 250 251 `ig` is built using a Docker container relying on [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx), so you don't have to worry 252 about installing dependencies: 253 254 ```bash 255 $ make ig 256 $ sudo cp ig /usr/local/bin/ 257 ``` 258 259 ## Experimental features 260 261 Inspektor Gadget has some experimental features disabled by default. Users can enable those 262 features, however they don't provide any stability and could be removed at any time. 263 264 `kubectl gadget deploy` provides an `--experimental` flag to enabled them. 265 266 ```bash 267 $ kubectl gadget deploy --experimental 268 $ kubectl logs -n gadget $PODNAME -f | grep -i experimental 269 ... 270 time="2023-06-15T15:20:03Z" level=info msg="Experimental features enabled" 271 ... 272 273 274 $ kubectl gadget trace exec 275 INFO[0000] Experimental features enabled 276 ... 277 ```