github.com/inspektor-gadget/inspektor-gadget@v0.28.1/docs/guides/run.md (about)

     1  ---
     2  title: 'Running a gadget'
     3  weight: 20
     4  description: >
     5    The run command allows to create an instance of a gadget.
     6  ---
     7  
     8  > ⚠️ This command is experimental and could change without prior notification. Only few gadgets are supported and we're working to extend this support.
     9  Check the installation guide to enable [experimental features](../getting-started/install-linux.md#experimental-features).
    10  
    11  The `run` command runs a gadget from an OCI image. By default, the `run` command will use following defaults to refer the OCI image:
    12  - `ghcr.io` as the registry
    13  - `inspektor-gadget/gadget` as the repository prefix
    14  - `latest` as the tag
    15  
    16  Check the different gadgets available in https://github.com/orgs/inspektor-gadget/packages.
    17  
    18  ## On Kubernetes
    19  
    20  ```bash
    21  $ kubectl gadget run trace_tcpconnect
    22  INFO[0000] Experimental features enabled
    23  K8S.NODE               K8S.NAMESPACE         K8S.POD               K8S.CONTAINER         PID     TASK        SRC                      DST
    24  ubuntu-hirsute         default               mypod2                mypod2                174085  wget        p/default/mypod2:37848   r/1.1.1.1:80
    25  ubuntu-hirsute         default               mypod2                mypod2                174085  wget        p/default/mypod2:33150   r/1.1.1.1:443
    26  
    27  $ kubectl gadget run trace_open
    28  INFO[0000] Experimental features enabled
    29  K8S.NODE               K8S.NAMESPACE          K8S.POD                K8S.CONTAINER          PID     COMM        UID      GID      RET FNAME
    30  ubuntu-hirsute         default                mypod2                 mypod2                 225071  sh          0        0        3   /
    31  ubuntu-hirsute         default                mypod2                 mypod2                 225071  sh          0        0        3   /root/.ash_history
    32  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /etc/ld.so.cache
    33  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/gl
    34  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/tl
    35  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/tl
    36  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/tl
    37  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/tl
    38  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/x8
    39  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/x8
    40  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/x8
    41  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64-linux-gnu/li
    42  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    43  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    44  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    45  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    46  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    47  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    48  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    49  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    50  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /usr/lib/x86_64-linux-gn
    51  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/glibc-hwcaps/x86-64
    52  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/tls/x86_64/x86_64/l
    53  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/tls/x86_64/libm.so.
    54  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/tls/x86_64/libm.so.
    55  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/tls/libm.so.6
    56  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64/x86_64/libm.
    57  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64/libm.so.6
    58  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        -2  /lib/x86_64/libm.so.6
    59  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        3   /lib/libm.so.6
    60  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        3   /lib/libresolv.so.2
    61  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        3   /lib/libc.so.6
    62  ubuntu-hirsute         default                mypod2                 mypod2                 242164  cat         0        0        3   /dev/null
    63  ```
    64  
    65  ### Private registries in Kubernetes
    66  
    67  In order to use private registries, you will need a [Kubernetes secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) having credentials to access the registry.
    68  
    69  There are two different ways to use this support:
    70  
    71  #### Defining a default secret when deploying Inspektor Gadget
    72  
    73  This approach creates a secret that will be used by default when pulling the gadget images. It requires to have a `docker-registry` secret named `gadget-pull-secret` in the `gadget` namespace:
    74  
    75  Let's create the `gadget` namespace if it doesn't exist:
    76  
    77  ```bash
    78  $ kubectl create namespace gadget
    79  ```
    80  
    81  then create the secret:
    82  
    83  ```bash
    84  $ kubectl create secret docker-registry gadget-pull-secret -n gadget --docker-server=MYSERVER --docker-username=MYUSERNAME --docker-password=MYPASSWORD
    85  ```
    86  
    87  or you can create the secret from a file:
    88  
    89  ```bash
    90  $ kubectl create secret docker-registry gadget-pull-secret -n gadget --from-file=.dockerconfigjson=$HOME/.docker/config.json
    91  ```
    92  
    93  then, deploy Inspektor Gadget:
    94  
    95  ```bash
    96  $ kubectl gadget deploy ...
    97  ```
    98  
    99  this secret will be used by default when running a gadget:
   100  
   101  
   102  ```bash
   103  $ kubectl gadget run myprivateregistry.io/trace_tcpconnect:latest
   104  ```
   105  
   106  #### Specifying the secret when running a gadget
   107  
   108  It's possible to pass a secret each time a gadget is run, you'd need to follow a similar approach as above to create the secret:
   109  
   110  ```bash
   111  # from credentials
   112  $ kubectl create secret docker-registry my-pull-secret -n gadget --docker-server=MYSERVER --docker-username=MYUSERNAME --docker-password=MYPASSWORD
   113  
   114  # from a file
   115  $ kubectl create secret docker-registry my-pull-secret -n gadget --from-file=.dockerconfigjson=$HOME/.docker/config.json
   116  ```
   117  
   118  Then, it can be used each time a gadget is run:
   119  
   120  ```bash
   121  $ kubectl gadget run myprivateregistry.io/trace_tcpconnect:latest --pull-secret my-pull-secret
   122  ```
   123  
   124  ## With `ig`
   125  
   126  ``` bash
   127  $ sudo ig run trace_tcpconnect
   128  INFO[0000] Experimental features enabled
   129  RUNTIME.CONTAINERNAME                                            PID     TASK             SRC                                DST
   130  mycontainer3                                                     1254254 wget             172.17.0.4:50072                   1.1.1.1:80
   131  mycontainer3                                                     1254254 wget             172.17.0.4:44408                   1.1.1.1:443
   132  
   133  $ sudo ig run trace_open
   134  INFO[0000] Experimental features enabled
   135  RUNTIME.CONTAINERNAME                               PID     COMM             UID      GID      RET       FNAME
   136  mycontainer3                                        62162   sh               0        0        3         /
   137  mycontainer3                                        62162   sh               0        0        3         /root/.ash_history
   138  mycontainer3                                        122110  cat              0        0        -2        /etc/ld.so.cache
   139  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64-linux-gnu/tls/x86_64/x86_64/libm.so.6
   140  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64-linux-gnu/tls/x86_64/libm.so.6
   141  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64-linux-gnu/tls/x86_64/libm.so.6
   142  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64-linux-gnu/tls/libm.so.6
   143  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64-linux-gnu/x86_64/x86_64/libm.so.6
   144  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64-linux-gnu/x86_64/libm.so.6
   145  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64-linux-gnu/x86_64/libm.so.6
   146  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64-linux-gnu/libm.so.6
   147  mycontainer3                                        122110  cat              0        0        -2        /usr/lib/x86_64-linux-gnu/tls/x86_64/x86_64/libm.so.6
   148  mycontainer3                                        122110  cat              0        0        -2        /usr/lib/x86_64-linux-gnu/tls/x86_64/libm.so.6
   149  mycontainer3                                        122110  cat              0        0        -2        /usr/lib/x86_64-linux-gnu/tls/x86_64/libm.so.6
   150  mycontainer3                                        122110  cat              0        0        -2        /usr/lib/x86_64-linux-gnu/tls/libm.so.6
   151  mycontainer3                                        122110  cat              0        0        -2        /usr/lib/x86_64-linux-gnu/x86_64/x86_64/libm.so.6
   152  mycontainer3                                        122110  cat              0        0        -2        /usr/lib/x86_64-linux-gnu/x86_64/libm.so.6
   153  mycontainer3                                        122110  cat              0        0        -2        /usr/lib/x86_64-linux-gnu/x86_64/libm.so.6
   154  mycontainer3                                        122110  cat              0        0        -2        /usr/lib/x86_64-linux-gnu/libm.so.6
   155  mycontainer3                                        122110  cat              0        0        -2        /lib/tls/x86_64/x86_64/libm.so.6
   156  mycontainer3                                        122110  cat              0        0        -2        /lib/tls/x86_64/libm.so.6
   157  mycontainer3                                        122110  cat              0        0        -2        /lib/tls/x86_64/libm.so.6
   158  mycontainer3                                        122110  cat              0        0        -2        /lib/tls/libm.so.6
   159  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64/x86_64/libm.so.6
   160  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64/libm.so.6
   161  mycontainer3                                        122110  cat              0        0        -2        /lib/x86_64/libm.so.6
   162  mycontainer3                                        122110  cat              0        0        3         /lib/libm.so.6
   163  mycontainer3                                        122110  cat              0        0        3         /lib/libresolv.so.2
   164  mycontainer3                                        122110  cat              0        0        3         /lib/libc.so.6
   165  mycontainer3                                        122110  cat              0        0        3         /dev/null
   166  ```