|
| 1 | +# How to build and run Gatling Operator |
| 2 | + |
| 3 | +This guide explains how to build Gatling Operator from its source code and run a sample in your local environment. |
| 4 | +In this guide, we use makefile to build and run Gatling Operator. |
| 5 | + |
| 6 | +- [How to build and run Gatling Operator](#how-to-build-and-run-gatling-operator) |
| 7 | + - [Pre-requisites](#pre-requisites) |
| 8 | + - [Get the Source code](#get-the-source-code) |
| 9 | + - [Install the tools](#install-the-tools) |
| 10 | + - [Create a Kubernetes cluster](#create-a-kubernetes-cluster) |
| 11 | + - [Build \& Deploy Gatling Operator](#build--deploy-gatling-operator) |
| 12 | + - [Create All in One manifest](#create-all-in-one-manifest) |
| 13 | + |
| 14 | +## Pre-requisites |
| 15 | + |
| 16 | +### Get the Source code |
| 17 | + |
| 18 | +The main repository is `st-tech/gatling-operator`. |
| 19 | +This contains the Gatling Operator source code and the build scripts. |
| 20 | + |
| 21 | +``` |
| 22 | +git clone https://github.com/st-tech/gatling-operator |
| 23 | +``` |
| 24 | + |
| 25 | +### Install the tools |
| 26 | + |
| 27 | +- [kubectl](https://kubernetes.io/docs/tasks/tools/) |
| 28 | +- [kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation) |
| 29 | +- [go](https://go.dev/doc/install) |
| 30 | + - go version must be 1.17 |
| 31 | + |
| 32 | +## Create a Kubernetes cluster |
| 33 | + |
| 34 | +Create a Kubernetes cluster for test Gatling Operator sample using kind. |
| 35 | + |
| 36 | +```bash |
| 37 | +make kind-create |
| 38 | +``` |
| 39 | + |
| 40 | +<details> |
| 41 | +<summary>sample output</summary> |
| 42 | + |
| 43 | +```bash |
| 44 | +❯ make kind-install |
| 45 | + |
| 46 | +No kind clusters found. |
| 47 | +Creating Cluster |
| 48 | +kind create cluster --name "gatling-cluster" --image=kindest/node:v1.19.11 --config ~/github/gatling-operator/config/kind/cluster.yaml |
| 49 | +Creating cluster "gatling-cluster" ... |
| 50 | + ✓ Ensuring node image (kindest/node:v1.19.11) 🖼 |
| 51 | + ✓ Preparing nodes 📦 📦 📦 |
| 52 | + ✓ Writing configuration 📜 |
| 53 | + ✓ Starting control-plane 🕹️ |
| 54 | + ✓ Installing CNI 🔌 |
| 55 | + ✓ Installing StorageClass 💾 |
| 56 | + ✓ Joining worker nodes 🚜 |
| 57 | +Set kubectl context to "kind-gatling-cluster" |
| 58 | +You can now use your cluster with: |
| 59 | + |
| 60 | +kubectl cluster-info --context kind-gatling-cluster |
| 61 | +``` |
| 62 | + |
| 63 | +</details> |
| 64 | + |
| 65 | +`make kind-create` command creates a Kubernetes cluster named `gatling-cluster` using kind. |
| 66 | +You can check the cluster details with the following commands. |
| 67 | +Get node information with kubectl and check that one control plane and one worker are ready. |
| 68 | + |
| 69 | +```bash |
| 70 | +❯ kind get clusters |
| 71 | +gatling-cluster |
| 72 | +❯ kubectl get node |
| 73 | +NAME STATUS ROLES AGE VERSION |
| 74 | +gatling-cluster-control-plane Ready master 150m v1.19.11 |
| 75 | +gatling-cluster-worker Ready <none> 150m v1.19.11 |
| 76 | +``` |
| 77 | + |
| 78 | +If your cluster contexts are not set, you can set the contexts with the following command. |
| 79 | + |
| 80 | +```bash |
| 81 | +kubectl config get-contexts |
| 82 | +kubectl config use-context kind-gatling-cluster |
| 83 | +``` |
| 84 | + |
| 85 | +## Build & Deploy Gatling Operator |
| 86 | + |
| 87 | +1. Build Gatling Operator with makefile. |
| 88 | + |
| 89 | + ```bash |
| 90 | + make build |
| 91 | + ``` |
| 92 | + |
| 93 | +2. Install CRD to your Kubernetes cluster. |
| 94 | + |
| 95 | + ```bash |
| 96 | + make install-crd |
| 97 | + ``` |
| 98 | + |
| 99 | + You can check the Gatling Operator CRD with the following command. |
| 100 | + |
| 101 | + ```bash |
| 102 | + ❯ kubectl get crd |
| 103 | + NAME CREATED AT |
| 104 | + gatlings.gatling-operator.tech.zozo.com 2023-08-01T04:43:54Z |
| 105 | + ``` |
| 106 | + |
| 107 | +3. Try to run Controller Manager in local |
| 108 | + |
| 109 | + ```bash |
| 110 | + make run |
| 111 | + ``` |
| 112 | + |
| 113 | + The commands runs Gatling Operator Controller Manager in your local environment. You can stop in ctrl+c. |
| 114 | + |
| 115 | + ``` |
| 116 | + ~/github/gatling-operator/bin/controller-gen "crd:trivialVersions=true,preserveUnknownFields=false" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases |
| 117 | + ~/github/gatling-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..." |
| 118 | + go fmt ./... |
| 119 | + api/v1alpha1/zz_generated.deepcopy.go |
| 120 | + go vet ./... |
| 121 | + go run ./main.go |
| 122 | + 2021-10-05T11:26:35.704+0900 INFO controller-runtime.metrics metrics server is starting to listen {"addr": ":8080"} |
| 123 | + 2021-10-05T11:26:35.705+0900 INFO setup starting manager |
| 124 | + 2021-10-05T11:26:35.705+0900 INFO controller-runtime.manager starting metrics server {"path": "/metrics"} |
| 125 | + 2021-10-05T11:26:35.705+0900 INFO controller-runtime.manager.controller.gatling Starting EventSource {"reconciler group": "gatling-operator.tech.zozo.com", "reconciler kind": "Gatling", "source": "kind source: /, Kind="} |
| 126 | + 2021-10-05T11:26:35.810+0900 INFO controller-runtime.manager.controller.gatling Starting Controller {"reconciler group": "gatling-operator.tech.zozo.com", "reconciler kind": "Gatling"} |
| 127 | + 2021-10-05T11:26:35.810+0900 INFO controller-runtime.manager.controller.gatling Starting workers {"reconciler group": "gatling-operator.tech.zozo.com", "reconciler kind": "Gatling", "worker count": 1} |
| 128 | + ... snip... |
| 129 | + ``` |
| 130 | + |
| 131 | +4. Build Docker image |
| 132 | + |
| 133 | + ``` |
| 134 | + : This build command image tag is %Y%m%d-%H%M%S format Timestamp |
| 135 | + make docker-build |
| 136 | + : You can define Image name and tag in this command |
| 137 | + make docker-build IMG=<your-registry>/zozo-gatling-operator:<tag> |
| 138 | + ``` |
| 139 | + |
| 140 | + <details> |
| 141 | + <summary>Sample</summary> |
| 142 | + |
| 143 | + ```bash |
| 144 | + ❯ DOCKER_REGISTRY=1234567890.dkr.ecr.ap-northeast-1.amazonaws.com |
| 145 | + ❯ DOCKER_IMAGE_REPO=zozo-gatling-operator |
| 146 | + ❯ DOCKER_IMAGE_TAG=v0.0.1 |
| 147 | + ❯ make docker-build IMG=${DOCKER_REGISTRY}/${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG} |
| 148 | + ❯ docker images |
| 149 | + REPOSITORY TAG IMAGE ID CREATED SIZE |
| 150 | + 1234567890.dkr.ecr.ap-northeast-1.amazonaws.com/zozo-gatling-operator v0.0.1 c66287dc8dc4 3 hours ago 46.2MB |
| 151 | + ``` |
| 152 | + |
| 153 | + </details> |
| 154 | + |
| 155 | +5. Deploy Controller to Cluster |
| 156 | + |
| 157 | + - Deploy to Local Kind Cluster |
| 158 | + |
| 159 | + ```bash |
| 160 | + make kind-deploy |
| 161 | + ``` |
| 162 | + |
| 163 | + - Deploy to Remote k8s Cluster |
| 164 | + |
| 165 | + ```bash |
| 166 | + make deploy IMG=${DOCKER_REGISTRY}/${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG} |
| 167 | + ``` |
| 168 | + |
| 169 | + - You can check gatling-operator controller forom the following command. |
| 170 | + |
| 171 | + ```bash |
| 172 | + ❯ kubectl get pods -n gatling-system |
| 173 | + NAME READY STATUS RESTARTS AGE |
| 174 | + gatling-operator-controller-manager-579bd7bc49-h46l2 2/2 Running 0 31m |
| 175 | + ``` |
| 176 | + |
| 177 | +6. Deploy sample scenario and check Gatling Operator works |
| 178 | + |
| 179 | + ```bash |
| 180 | + kustomize build config/samples | kubectl apply -f - |
| 181 | + ``` |
| 182 | + |
| 183 | +## Create All in One manifest |
| 184 | + |
| 185 | +This command creates an all in one manifest for Gatling Operator. |
| 186 | +All in One manifest create CRD and Gatling Operator Controller. |
| 187 | + |
| 188 | +```bash |
| 189 | +make manifests-release IMG=<your-registry>/zozo-gatling-operator:<tag> |
| 190 | +``` |
| 191 | + |
| 192 | +You can apply Gatling Operator to your Kubernetes cluster with the following command. |
| 193 | + |
| 194 | +```bash |
| 195 | +kubectl apply -f gatling-operator.yaml |
| 196 | +``` |
0 commit comments