From 4973441f8541d37525d048c71c5ded36ada2c52f Mon Sep 17 00:00:00 2001 From: adrianc Date: Tue, 15 Aug 2023 17:34:57 +0300 Subject: [PATCH 1/2] Add local dev env via skaffold - create new dev overlay - create skaffold yaml - add tasks to create/clean local k8s dev env - update README Signed-off-by: adrianc --- README.md | 30 +++++++++++++++++++ Taskfile.dist.yaml | 1 + .../k8s/overlays/dev/kustomization.yaml | 18 +++++++++++ skaffold.yaml | 21 +++++++++++++ taskfiles/LocalDev.yaml | 18 +++++++++++ 5 files changed, 88 insertions(+) create mode 100644 deployment/k8s/overlays/dev/kustomization.yaml create mode 100644 skaffold.yaml create mode 100644 taskfiles/LocalDev.yaml diff --git a/README.md b/README.md index 369755b..63ee4c5 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ - [Build and Run Locally](#build-and-run-locally) - [Prerequisites](#prerequisites-1) - [Build \& Run](#build--run) + - [Build \& Run in local K8s cluster](#build--run-in-local-k8s-cluster) + - [Install Prerequisites](#install-prerequisites) + - [Create local k8s development environment](#create-local-k8s-development-environment) + - [Cleanup local k8s development environment](#cleanup-local-k8s-development-environment) ## Overview @@ -192,3 +196,29 @@ task build > __Note__: To build container image run `task image:build`. to deploy this image in your k8 cluster, you should re-tag and upload to your > own image registry, then create an overlay for exsiting deployment which overrides the image name with your own image path. + + +### Build & Run in local K8s cluster + +For local development it is possible to use [skaffold](https://skaffold.dev/) to deploy +local changes onto a local k8s cluster. + +#### Install Prerequisites + +1. [install Docker](https://docs.docker.com/engine/install/) +2. [install minikube](https://minikube.sigs.k8s.io/docs/start/) +3. [install skaffold](https://skaffold.dev/docs/install/#standalone-binary) + +#### Create local k8s development environment + +```shell +task -o interleaved localdev:start +``` + +To trigger a rebuild, press any key in the current shell. + +#### Cleanup local k8s development environment + +```shell +task -o interleaved localdev:clean +``` diff --git a/Taskfile.dist.yaml b/Taskfile.dist.yaml index afbd635..731fd7a 100644 --- a/Taskfile.dist.yaml +++ b/Taskfile.dist.yaml @@ -30,6 +30,7 @@ includes: BIN_DIR: "{{.LOCAL_BIN}}" kind: ./taskfiles/Kind.yaml image: ./taskfiles/Image.yaml + localdev: ./taskfiles/LocalDev.yaml tasks: clean: diff --git a/deployment/k8s/overlays/dev/kustomization.yaml b/deployment/k8s/overlays/dev/kustomization.yaml new file mode 100644 index 0000000..cbd5f65 --- /dev/null +++ b/deployment/k8s/overlays/dev/kustomization.yaml @@ -0,0 +1,18 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: nic-feature-discovery + +patches: + - target: + version: v1 + group: apps + kind: DaemonSet + name: nic-feature-discovery-ds + patch: |- + - op: replace + path: /spec/template/spec/containers/0/args + value: ["--v=5", "--logging-format=text"] + +resources: +- ../default diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000..9a9a45e --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,21 @@ +apiVersion: skaffold/v4beta6 +kind: Config +metadata: + name: nic-feature-discovery +build: + artifacts: + - image: ghcr.io/mellanox/nic-feature-discovery + docker: + dockerfile: Dockerfile +manifests: + kustomize: + paths: + - deployment/k8s/base +profiles: + - name: local-dev + manifests: + kustomize: + paths: + - deployment/k8s/overlays/dev + activation: + - command: dev diff --git a/taskfiles/LocalDev.yaml b/taskfiles/LocalDev.yaml new file mode 100644 index 0000000..4025a7e --- /dev/null +++ b/taskfiles/LocalDev.yaml @@ -0,0 +1,18 @@ + version: '3' + + tasks: + start: + desc: deploy using skaffold to k8s using current kube context (run with -o interleaved for interactive output) + vars: + NFD_VERSION: v0.13.3 + cmd: | + minikube --profile nfd-dev start + # this one will point docker cli to the same daemon as used by minikube nfd-dev cluster + # that way skaffold will build images in the correct local repo. + eval $(minikube -p nfd-dev docker-env) + kubectl apply -k "https://github.com/kubernetes-sigs/node-feature-discovery/deployment/overlays/default?ref={{.NFD_VERSION}}" + skaffold dev --trigger=manual + + clean: + desc: clean local k8s dev cluster + cmd: minikube --profile nfd-dev delete From aa28deaf51ad64144522f1c5d87cfd7444bbbb06 Mon Sep 17 00:00:00 2001 From: adrianc Date: Wed, 16 Aug 2023 14:21:26 +0300 Subject: [PATCH 2/2] Add support for deploying on existing cluster Signed-off-by: adrianc --- README.md | 42 +++++++++++++++++++++++++++++++---------- taskfiles/LocalDev.yaml | 10 ++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 63ee4c5..72f6ede 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,12 @@ - [Build and Run Locally](#build-and-run-locally) - [Prerequisites](#prerequisites-1) - [Build \& Run](#build--run) - - [Build \& Run in local K8s cluster](#build--run-in-local-k8s-cluster) + - [Build \& Run In K8s Cluster For Development](#build--run-in-k8s-cluster-for-development) - [Install Prerequisites](#install-prerequisites) - - [Create local k8s development environment](#create-local-k8s-development-environment) - - [Cleanup local k8s development environment](#cleanup-local-k8s-development-environment) + - [Local Cluster](#local-cluster) + - [Create Local K8s Development Environment](#create-local-k8s-development-environment) + - [Cleanup Local K8s Development Environment](#cleanup-local-k8s-development-environment) + - [Remote K8s Cluster (existing cluster)](#remote-k8s-cluster-existing-cluster) ## Overview @@ -198,18 +200,21 @@ task build > own image registry, then create an overlay for exsiting deployment which overrides the image name with your own image path. -### Build & Run in local K8s cluster +### Build & Run In K8s Cluster For Development -For local development it is possible to use [skaffold](https://skaffold.dev/) to deploy -local changes onto a local k8s cluster. +For development [skaffold](https://skaffold.dev/) is used to deploy +local changes onto a K8s cluster. #### Install Prerequisites 1. [install Docker](https://docs.docker.com/engine/install/) -2. [install minikube](https://minikube.sigs.k8s.io/docs/start/) -3. [install skaffold](https://skaffold.dev/docs/install/#standalone-binary) +2. [install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) +3. [install minikube](https://minikube.sigs.k8s.io/docs/start/) +4. [install skaffold](https://skaffold.dev/docs/install/#standalone-binary) -#### Create local k8s development environment +#### Local Cluster + +##### Create Local K8s Development Environment ```shell task -o interleaved localdev:start @@ -217,8 +222,25 @@ task -o interleaved localdev:start To trigger a rebuild, press any key in the current shell. -#### Cleanup local k8s development environment +##### Cleanup Local K8s Development Environment ```shell task -o interleaved localdev:clean ``` + +#### Remote K8s Cluster (existing cluster) + +For this deployment option you should provide the following environment variables + +- `LOCALDEV_IMAGE_REPO`: image repository which skaffold will use. +- `LOCALDEV_KUBECONFIG`: optional, path to kubeconfig file which will be used by skaffold to access k8s cluster. +- `LOCALDEV_KUBECONTEXT`: optional. name of kube context which will be used by skaffold to access k8s cluster. + +```shell +LOCALDEV_IMAGE_REPO=quay.io/myuser LOCALDEV_KUBECONTEXT=my-remote-cluster task -o interleaved localdev:deploy +``` + +To trigger a rebuild, press any key in the current shell. + +>__NOTE__: if `LOCALDEV_KUBECONFIG` and `LOCALDEV_KUBECONTEXT` are not provided, the current context pointed by +> kubectl will be used. diff --git a/taskfiles/LocalDev.yaml b/taskfiles/LocalDev.yaml index 4025a7e..e19de2b 100644 --- a/taskfiles/LocalDev.yaml +++ b/taskfiles/LocalDev.yaml @@ -16,3 +16,13 @@ clean: desc: clean local k8s dev cluster cmd: minikube --profile nfd-dev delete + + deploy: + desc: deploy on pre-created cluster + vars: + LOCALDEV_IMAGE_REPO: '{{.LOCALDEV_IMAGE_REPO | default "harbor.mellanox.com/cloud-orchestration-dev"}}' + #LOCALDEV_KUBECONFIG: "/path/to/kubeconfig" <- optional, pass in via env var + #LOCALDEV_KUBECONTEXT: "kube-context-name" <- optional, pass in via env var + cmd: | + export SK_FLAGS="{{if .LOCALDEV_KUBECONFIG}}--kubeconfig={{.LOCALDEV_KUBECONFIG}}{{else}}{{if .LOCALDEV_KUBECONTEXT}}--kube-context={{.LOCALDEV_KUBECONTEXT}}{{end}}{{end}}" + skaffold dev --trigger=manual --default-repo={{.LOCALDEV_IMAGE_REPO}} $SK_FLAGS