1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

docs: add section for deploying a local build (#4458)

* docs: add section for deploying a local build

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

* review

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

* review

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

* fix merge

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-08-31 10:06:12 +02:00 committed by GitHub
parent f243a7dd84
commit a53ad6a5dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 107 additions and 12 deletions

View file

@ -13,6 +13,10 @@ It contains instructions to build, run, and test Kyverno.
- [Pushing images](#pushing-images) - [Pushing images](#pushing-images)
- [Pushing images with docker](#pushing-images-with-docker) - [Pushing images with docker](#pushing-images-with-docker)
- [Pushing images with ko](#pushing-images-with-ko) - [Pushing images with ko](#pushing-images-with-ko)
- [Deploying a local build](#deploying-a-local-build)
- [Create a local cluster](#create-a-local-cluster)
- [Build and load local images](#build-and-load-local-images)
- [Deploy with helm](#deploy-with-helm)
## Tools ## Tools
@ -281,6 +285,69 @@ make ko-publish-cli-dev
The resulting image should be available remotely, named `ghcr.io/kyverno/kyverno-cli` (by default, if `REGISTRY` environment variable was not set). The resulting image should be available remotely, named `ghcr.io/kyverno/kyverno-cli` (by default, if `REGISTRY` environment variable was not set).
## Deploying a local build
After [building local images](#building-local-images), it is often useful to deploy those images in a local cluster.
We use [KinD](https://kind.sigs.k8s.io/) to create local clusters easily.
### Create a local cluster
If you already have a local KinD cluster running, you can skip this step.
To create a local KinD cluster, run:
```console
make kind-create-cluster
```
You can override the k8s version by setting the `KIND_IMAGE` environment variable (default value is `kindest/node:v1.24.0`).
You can also override the KinD cluster name by setting the `KIND_NAME` environment variable (default value is `kind`).
### Build and load local images
To build local images and load them on a local KinD cluster, run:
```console
# build kyvernopre image and load it in KinD cluster
make kind-load-kyvernopre
```
or
```console
# build kyverno image and load it in KinD cluster
make kind-load-kyverno
```
or
```console
# build kyvernopre and kyverno images and load them in KinD cluster
make kind-load-all
```
You can override the KinD cluster name by setting the `KIND_NAME` environment variable (default value is `kind`).
### Deploy with helm
To build local images, load them on a local KinD cluster, and deploy helm charts, run:
```console
# build images, load them in KinD cluster and deploy kyverno helm chart
make kind-deploy-kyverno
```
or
```console
# deploy kyverno-policies helm chart
make kind-deploy-kyverno-policies
```
or
```console
# build images, load them in KinD cluster and deploy helm charts
make kind-deploy-all
```
This will build local images, load built images in every node of the KinD cluster, and deploy `kyverno` and/or `kyverno-policies` helm charts in the cluster (overriding image repositories and tags).
> **Note**: This actually uses `ko` to build local images.
You can override the KinD cluster name by setting the `KIND_NAME` environment variable (default value is `kind`).
## Building and publishing an image locally ## Building and publishing an image locally
First, make sure you [install `ko`](https://github.com/google/ko#install) First, make sure you [install `ko`](https://github.com/google/ko#install)

View file

@ -18,6 +18,7 @@ IMAGE_TAG ?= $(GIT_VERSION)
K8S_VERSION ?= $(shell kubectl version --short | grep -i server | cut -d" " -f3 | cut -c2-) K8S_VERSION ?= $(shell kubectl version --short | grep -i server | cut -d" " -f3 | cut -c2-)
TEST_GIT_BRANCH ?= main TEST_GIT_BRANCH ?= main
KIND_IMAGE ?= kindest/node:v1.24.0 KIND_IMAGE ?= kindest/node:v1.24.0
KIND_NAME ?= kind
GOOS ?= $(shell go env GOOS) GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH) GOARCH ?= $(shell go env GOARCH)
@ -493,22 +494,49 @@ verify-helm: gen-helm ## Check Helm charts are up to date
@echo 'To correct this, locally run "make gen-helm", commit the changes, and re-run tests.' @echo 'To correct this, locally run "make gen-helm", commit the changes, and re-run tests.'
git diff --quiet --exit-code charts git diff --quiet --exit-code charts
################################## ########
# HELP # KIND #
################################## ########
.PHONY: help .PHONY: kind-create-cluster
help: ## Shows the available commands kind-create-cluster: $(KIND) ## Create KinD cluster
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @$(KIND) create cluster --name $(KIND_NAME) --image $(KIND_IMAGE)
.PHONY: kind-deploy .PHONY: kind-delete-cluster
kind-deploy: $(KIND) ko-build-kyvernopre-local ko-build-kyverno-local kind-delete-cluster: $(KIND) ## Delete KinD cluster
$(KIND) load docker-image $(INITC_KIND_IMAGE):$(IMAGE_TAG_DEV) @$(KIND) delete cluster --name $(KIND_NAME)
$(KIND) load docker-image $(KYVERNO_KIND_IMAGE):$(IMAGE_TAG_DEV)
helm upgrade --install kyverno --namespace kyverno --wait --create-namespace ./charts/kyverno \ .PHONY: kind-load-kyvernopre
kind-load-kyvernopre: $(KIND) ko-build-kyvernopre ## Build kyvernopre image and load it in KinD cluster
@$(KIND) load docker-image --name $(KIND_NAME) $(INITC_KIND_IMAGE):$(IMAGE_TAG_DEV)
.PHONY: kind-load-kyverno
kind-load-kyverno: $(KIND) ko-build-kyverno ## Build kyverno image and load it in KinD cluster
@$(KIND) load docker-image --name $(KIND_NAME) $(KYVERNO_KIND_IMAGE):$(IMAGE_TAG_DEV)
.PHONY: kind-load-all
kind-load-all: kind-load-kyvernopre kind-load-kyverno ## Build images and load them in KinD cluster
.PHONY: kind-deploy-kyverno
kind-deploy-kyverno: kind-load-all ## Build images, load them in KinD cluster and deploy kyverno helm chart
@helm upgrade --install kyverno --namespace kyverno --wait --create-namespace ./charts/kyverno \
--set image.repository=$(KYVERNO_KIND_IMAGE) \ --set image.repository=$(KYVERNO_KIND_IMAGE) \
--set image.tag=$(IMAGE_TAG_DEV) \ --set image.tag=$(IMAGE_TAG_DEV) \
--set initImage.repository=$(INITC_KIND_IMAGE) \ --set initImage.repository=$(INITC_KIND_IMAGE) \
--set initImage.tag=$(IMAGE_TAG_DEV) \ --set initImage.tag=$(IMAGE_TAG_DEV) \
--set extraArgs={--autogenInternals=true} --set extraArgs={--autogenInternals=true}
helm upgrade --install kyverno-policies --namespace kyverno --create-namespace ./charts/kyverno-policies
.PHONY: kind-deploy-kyverno-policies
kind-deploy-kyverno-policies: ## Deploy kyverno-policies helm chart
@helm upgrade --install kyverno-policies --namespace kyverno --create-namespace ./charts/kyverno-policies
.PHONY: kind-deploy-all
kind-deploy-all: | kind-deploy-kyverno kind-deploy-kyverno-policies ## Build images, load them in KinD cluster and deploy helm charts
########
# HELP #
########
.PHONY: help
help: ## Shows the available commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'