sigs.k8s.io/cluster-api-provider-aws@v1.5.5/docs/book/src/development/tilt-setup.md (about)

     1  # Developing Cluster API Provider AWS  with Tilt
     2  
     3  This document describes how to use kind and [Tilt][tilt] for a simplified workflow that offers easy deployments and rapid iterative builds.
     4  Before the next steps, make sure [initial setup for development environment][Initial-setup-for-development-environment] steps are complete.
     5  
     6  Also, visit the [Cluster API documentation on Tilt][cluster_api_tilt] for more information on how to set up your development environment.
     7  
     8  [tilt]: https://tilt.dev
     9  [cluster_api_tilt]: https://cluster-api.sigs.k8s.io/developer/tilt.html
    10  [Initial-setup-for-development-environment]: ./development.md/#initial-setup-for-development-environment
    11  
    12  ## Create a kind cluster
    13  
    14  First, make sure you have a kind cluster and that your `KUBECONFIG` is set up correctly:
    15  
    16  ``` bash
    17  kind create cluster
    18  ```
    19  
    20  This local cluster will be running all the cluster api controllers and become the management cluster which then can be used to spin up workload clusters on AWS.
    21  
    22  ## Get the source
    23  
    24  Get the source for core cluster-api for development with Tilt along with cluster-api-provider-aws.
    25  
    26  ```bash
    27  cd "$(go env GOPATH)"
    28  mkdir sigs.k8s.io
    29  cd sigs.k8s.io/
    30  git clone git@github.com:kubernetes-sigs/cluster-api.git
    31  cd cluster-api
    32  git fetch upstream
    33  ```
    34  
    35  ## Create a tilt-settings.json file
    36  
    37  Next, create a `tilt-settings.json` file and place it in your local copy of `cluster-api`. Here is an example:
    38  
    39  **Example `tilt-settings.json` for CAPA clusters:**
    40  
    41  ```json
    42  {
    43    "enable_providers": [
    44      "kubeadm-bootstrap",
    45      "kubeadm-control-plane",
    46      "aws"
    47    ],
    48    "default_registry": "gcr.io/your-project-name-here",
    49    "provider_repos": [
    50      "/Users/username/go/src/sigs.k8s.io/cluster-api-provider-aws"
    51    ],
    52    "kustomize_substitutions": {
    53      "EXP_CLUSTER_RESOURCE_SET": "true",
    54      "EXP_MACHINE_POOL": "true",
    55      "EVENT_BRIDGE_INSTANCE_STATE": "true",
    56      "AWS_B64ENCODED_CREDENTIALS": "W2RlZmFZSZnRg==",
    57      "EXP_EKS_FARGATE": "false",
    58      "CAPA_EKS_IAM": "false",
    59      "CAPA_EKS_ADD_ROLES": "false",
    60      "EXP_BOOTSTRAP_FORMAT_IGNITION": "true"
    61    },
    62    "extra_args": {
    63      "aws": ["--v=2"]
    64    }
    65  }
    66  ```
    67  
    68  **Example `tilt-settings.json` for EKS managed clusters prior to CAPA v0.7.0:**
    69  
    70  ```json
    71  {
    72      "default_registry": "gcr.io/your-project-name-here",
    73      "provider_repos": ["../cluster-api-provider-aws"],
    74      "enable_providers": ["eks-bootstrap", "eks-controlplane", "kubeadm-bootstrap", "kubeadm-control-plane", "aws"],
    75      "kustomize_substitutions": {
    76          "AWS_B64ENCODED_CREDENTIALS": "W2RlZmFZSZnRg==",
    77          "EXP_EKS": "true",
    78          "EXP_EKS_IAM": "true",
    79          "EXP_MACHINE_POOL": "true"
    80      },
    81      "extra_args": {
    82          "aws": ["--v=2"],
    83          "eks-bootstrap": ["--v=2"],
    84          "eks-controlplane": ["--v=2"]
    85      }
    86    }
    87  ```
    88  
    89  ### Debugging
    90  
    91  If you would like to debug CAPA (or core CAPI / another provider) you can run the provider with delve. This will then allow you to attach to delve and debug.
    92  
    93  To do this you need to use the **debug** configuration in **tilt-settings.json**. Full details of the options can be seen [here](https://cluster-api.sigs.k8s.io/developer/tilt.html).
    94  
    95  An example **tilt-settings.json**:
    96  
    97  ```json
    98  {
    99    "enable_providers": [
   100      "kubeadm-bootstrap",
   101      "kubeadm-control-plane",
   102      "aws"
   103    ],
   104    "default_registry": "gcr.io/your-project-name-here",
   105    "provider_repos": [
   106      "/Users/username/go/src/sigs.k8s.io/cluster-api-provider-aws"
   107    ],
   108    "kustomize_substitutions": {
   109      "EXP_CLUSTER_RESOURCE_SET": "true",
   110      "EXP_MACHINE_POOL": "true",
   111      "EVENT_BRIDGE_INSTANCE_STATE": "true",
   112      "AWS_B64ENCODED_CREDENTIALS": "W2RlZmFZSZnRg==",
   113      "EXP_EKS_FARGATE": "false",
   114      "CAPA_EKS_IAM": "false",
   115      "CAPA_EKS_ADD_ROLES": "false"
   116    },
   117    "extra_args": {
   118      "aws": ["--v=2"]
   119    }
   120    "debug": {
   121      "aws": {
   122        "continue": true,
   123        "port": 30000
   124      }
   125    }
   126  }
   127  ```
   128  
   129  Once you have run tilt (see section below) you will be able to connect to the running instance of delve.
   130  
   131  For vscode, you can use the a launch configuration like this:
   132  
   133  ```json
   134      {
   135          "name": "Connect to CAPA",
   136          "type": "go",
   137          "request": "attach",
   138          "mode": "remote",
   139          "remotePath": "",
   140          "port": 30000,
   141          "host": "127.0.0.1",
   142          "showLog": true,
   143          "trace": "log",
   144          "logOutput": "rpc"
   145      }
   146  ```
   147  
   148  For GoLand/IntelliJ add a new run configuration following [these instructions](https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#step-3-create-the-remote-run-debug-configuration-on-the-client-computer).
   149  
   150  Or you could use delve directly from the CLI using a command similar to this:
   151  
   152  ```bash
   153  dlv-dap connect 127.0.0.1:3000
   154  ```
   155  
   156  ## Run Tilt!
   157  
   158  To launch your development environment, run:
   159  
   160  ``` bash
   161  tilt up
   162  ```
   163  
   164  kind cluster becomes a management cluster after this point, check the pods running on the kind cluster `kubectl get pods -A`.
   165  
   166  ## Create workload clusters
   167  
   168  Set the following variables for both CAPA and EKS managed clusters:
   169  
   170  ```bash
   171  export AWS_SSH_KEY_NAME=<sshkeypair>
   172  export KUBERNETES_VERSION=v1.20.2
   173  export CLUSTER_NAME=capi-<test-clustename>
   174  export CONTROL_PLANE_MACHINE_COUNT=1
   175  export AWS_CONTROL_PLANE_MACHINE_TYPE=t3.large
   176  export WORKER_MACHINE_COUNT=1
   177  export AWS_NODE_MACHINE_TYPE=t3.large
   178  ```
   179  
   180  Set the following variables for only EKS managed clusters:
   181  
   182  ```bash
   183  export AWS_EKS_ROLE_ARN=arn:aws:iam::<accountid>:role/aws-service-role/eks.amazonaws.com/AWSServiceRoleForAmazonEKS
   184  export EKS_KUBERNETES_VERSION=v1.15
   185  ```
   186  
   187  **Create CAPA managed workload cluster:**
   188  
   189  ```bash
   190  cat templates/cluster-template.yaml
   191  cat templates/cluster-template.yaml | $HOME/go/bin/envsubst > test-cluster.yaml
   192  kubectl apply -f test-cluster.yaml
   193  ```
   194  
   195  **Create EKS workload cluster:**
   196  
   197  ```bash
   198  cat templates/cluster-template-eks.yaml
   199  cat templates/cluster-template-eks.yaml | $HOME/go/bin/envsubst > test-cluster.yaml
   200  kubectl apply -f test-cluster.yaml
   201  ```
   202  
   203  Check the tilt logs and wait for the clusters to be created.
   204  
   205  ## Clean up
   206  
   207  Before deleting the kind cluster, make sure you delete all the workload clusters.
   208  
   209  ```bash
   210  kubectl delete cluster <clustername>
   211  tilt up (ctrl-c)
   212  kind delete cluster
   213  ```
   214  
   215  ## Troubleshooting
   216  
   217  - Make sure you have at least three available spaces EIP and NAT Gateways to be created
   218  - If your git starts throwing this error
   219  
   220  ```bash
   221  flag provided but not defined: -variables
   222  Usage: envsubst [options...] <input>
   223  ```
   224  
   225  you might need to reinstall the system `envsubst`
   226  
   227  ```bash
   228  brew install gettetxt
   229  # or
   230  brew reinstall gettext
   231  ```
   232  
   233  Make sure you specify which `envsubst` you are using