From 27811c742e88285e1c7e3b103ead3a50461bafb6 Mon Sep 17 00:00:00 2001 From: Ronen Schaffer Date: Wed, 27 Apr 2022 14:51:04 +0300 Subject: [PATCH 1/5] Load local image in local-deploy --- Makefile | 12 +++++++++++- contrib/kubernetes/deployment.yaml | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9e4975e6c..d8b110141 100644 --- a/Makefile +++ b/Makefile @@ -148,9 +148,19 @@ push-image: build-image ## Push latest image # note: to deploy with custom image tag use: DOCKER_TAG=test make deploy .PHONY: deploy -deploy: ## Deploy the image +deploy: build-image ## Deploy the image sed 's|%DOCKER_IMG%|$(DOCKER_IMG)|g;s|%DOCKER_TAG%|$(DOCKER_TAG)|g' contrib/kubernetes/deployment.yaml > /tmp/deployment.yaml kubectl create configmap flowlogs-pipeline-configuration --from-file=flowlogs-pipeline.conf.yaml=$(FLP_CONF_FILE) +# The following "if" statement is still part of the "deploy" recipe. It couldn't be indented with tabs because it will +# be considered as part of the recipe. It could be indented with spaces but I find it confusing. +# https://stackoverflow.com/a/28720186/2749989 +ifeq ($(OCI_RUNTIME),$(shell which docker)) +# This is an optimization for docker provider. "kind load docker-image" can load an image directly from docker's +# local registry. For other providers (i.e. podman), we must use "kind load image-archive" instead. + $(KIND) load docker-image $(DOCKER_IMG):$(DOCKER_TAG) +else + $(OCI_RUNTIME) save $(DOCKER_IMG):$(DOCKER_TAG) | kind load image-archive - +endif kubectl apply -f /tmp/deployment.yaml kubectl rollout status "deploy/flowlogs-pipeline" --timeout=600s diff --git a/contrib/kubernetes/deployment.yaml b/contrib/kubernetes/deployment.yaml index 496ccbf02..e06204f64 100644 --- a/contrib/kubernetes/deployment.yaml +++ b/contrib/kubernetes/deployment.yaml @@ -23,7 +23,7 @@ spec: - containerPort: 6343 - containerPort: 2055 - containerPort: 2056 - imagePullPolicy: Always + imagePullPolicy: Never volumeMounts: - name: configuration mountPath: "/etc/flowlogs-pipeline/" From c9d134584991f03eff1097f291e659194bf032e1 Mon Sep 17 00:00:00 2001 From: Ronen Schaffer Date: Wed, 27 Apr 2022 16:53:57 +0300 Subject: [PATCH 2/5] Remove a trivial comment --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index d8b110141..feb2e1495 100644 --- a/Makefile +++ b/Makefile @@ -151,9 +151,6 @@ push-image: build-image ## Push latest image deploy: build-image ## Deploy the image sed 's|%DOCKER_IMG%|$(DOCKER_IMG)|g;s|%DOCKER_TAG%|$(DOCKER_TAG)|g' contrib/kubernetes/deployment.yaml > /tmp/deployment.yaml kubectl create configmap flowlogs-pipeline-configuration --from-file=flowlogs-pipeline.conf.yaml=$(FLP_CONF_FILE) -# The following "if" statement is still part of the "deploy" recipe. It couldn't be indented with tabs because it will -# be considered as part of the recipe. It could be indented with spaces but I find it confusing. -# https://stackoverflow.com/a/28720186/2749989 ifeq ($(OCI_RUNTIME),$(shell which docker)) # This is an optimization for docker provider. "kind load docker-image" can load an image directly from docker's # local registry. For other providers (i.e. podman), we must use "kind load image-archive" instead. From 4b42f5336754045fb007316eefc3225d779de1ba Mon Sep 17 00:00:00 2001 From: Ronen Schaffer Date: Wed, 27 Apr 2022 17:00:26 +0300 Subject: [PATCH 3/5] Add kind-load-image target --- Makefile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index feb2e1495..9637bef47 100644 --- a/Makefile +++ b/Makefile @@ -148,16 +148,9 @@ push-image: build-image ## Push latest image # note: to deploy with custom image tag use: DOCKER_TAG=test make deploy .PHONY: deploy -deploy: build-image ## Deploy the image +deploy: ## Deploy the image sed 's|%DOCKER_IMG%|$(DOCKER_IMG)|g;s|%DOCKER_TAG%|$(DOCKER_TAG)|g' contrib/kubernetes/deployment.yaml > /tmp/deployment.yaml kubectl create configmap flowlogs-pipeline-configuration --from-file=flowlogs-pipeline.conf.yaml=$(FLP_CONF_FILE) -ifeq ($(OCI_RUNTIME),$(shell which docker)) -# This is an optimization for docker provider. "kind load docker-image" can load an image directly from docker's -# local registry. For other providers (i.e. podman), we must use "kind load image-archive" instead. - $(KIND) load docker-image $(DOCKER_IMG):$(DOCKER_TAG) -else - $(OCI_RUNTIME) save $(DOCKER_IMG):$(DOCKER_TAG) | kind load image-archive - -endif kubectl apply -f /tmp/deployment.yaml kubectl rollout status "deploy/flowlogs-pipeline" --timeout=600s @@ -230,6 +223,16 @@ create-kind-cluster: $(KIND) ## Create cluster delete-kind-cluster: $(KIND) ## Delete cluster $(KIND) delete cluster +.PHONY: kind-load-image +kind-load-image: ## Load image to kind +ifeq ($(OCI_RUNTIME),$(shell which docker)) +# This is an optimization for docker provider. "kind load docker-image" can load an image directly from docker's +# local registry. For other providers (i.e. podman), we must use "kind load image-archive" instead. + $(KIND) load docker-image $(DOCKER_IMG):$(DOCKER_TAG) +else + $(OCI_RUNTIME) save $(DOCKER_IMG):$(DOCKER_TAG) | kind load image-archive - +endif + ##@ metrics .PHONY: generate-configuration @@ -243,7 +246,7 @@ generate-configuration: $(KIND) ## Generate metrics configuration ##@ End2End .PHONY: local-deployments-deploy -local-deployments-deploy: $(KIND) deploy-prometheus deploy-loki deploy-grafana deploy deploy-netflow-simulator +local-deployments-deploy: $(KIND) deploy-prometheus deploy-loki deploy-grafana build-image kind-load-image deploy deploy-netflow-simulator kubectl get pods kubectl rollout status -w deployment/flowlogs-pipeline kubectl logs -l app=flowlogs-pipeline From b7e474d9af06bf726160935bdf2513fd164944e7 Mon Sep 17 00:00:00 2001 From: Ronen Schaffer Date: Wed, 27 Apr 2022 18:26:37 +0300 Subject: [PATCH 4/5] Fix 'kind load image-archive' command It doesn't support input from STDIN --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9637bef47..7a577c248 100644 --- a/Makefile +++ b/Makefile @@ -230,7 +230,11 @@ ifeq ($(OCI_RUNTIME),$(shell which docker)) # local registry. For other providers (i.e. podman), we must use "kind load image-archive" instead. $(KIND) load docker-image $(DOCKER_IMG):$(DOCKER_TAG) else - $(OCI_RUNTIME) save $(DOCKER_IMG):$(DOCKER_TAG) | kind load image-archive - + $(eval tmpfile="/tmp/flp.tar") + -rm $(tmpfile) + $(OCI_RUNTIME) save $(DOCKER_IMG):$(DOCKER_TAG) -o $(tmpfile) + $(KIND) load image-archive $(tmpfile) + -rm $(tmpfile) endif ##@ metrics From 1ce62005a14c185768d1b6a812d070aa49b97d5b Mon Sep 17 00:00:00 2001 From: Ronen Schaffer Date: Tue, 3 May 2022 12:33:52 +0300 Subject: [PATCH 5/5] Change imagePullPolicy to IfNotPresent When deployed on KinD, the image is pre-pushed to KinD from the local registry. When deployed on OCP, OCP will pull the image from quay.io. --- contrib/kubernetes/deployment.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/kubernetes/deployment.yaml b/contrib/kubernetes/deployment.yaml index e06204f64..c49cfaadd 100644 --- a/contrib/kubernetes/deployment.yaml +++ b/contrib/kubernetes/deployment.yaml @@ -23,7 +23,9 @@ spec: - containerPort: 6343 - containerPort: 2055 - containerPort: 2056 - imagePullPolicy: Never + # When deployed on KinD, the image is pre-pushed to KinD from the local registry. + # When deployed on OCP, OCP will pull the image from quay.io. + imagePullPolicy: IfNotPresent volumeMounts: - name: configuration mountPath: "/etc/flowlogs-pipeline/"