From bdb197eb5c7969a24d12e110f60a3bd63b055732 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Wed, 25 Sep 2019 12:37:17 +0200 Subject: [PATCH] Use `flux` namespace in `deploy/` examples This is so that the configuration is not effected by e.g. a namespace context set in the `kubectl` config of the user, as this caused problems during the creation of the `ClusterRoleBinding` which was set to the `default` namespace, while the resources themselves would be created in the user their configured namespace. It also simplifies the 'Get started with Kustomize' guide, as a user does no longer need to create the namespace as a prerequisite but is still able to overwrite it by adding a `namespace: ` to their `kustomization.yaml`. --- deploy/flux-account.yaml | 3 +- deploy/flux-deployment.yaml | 1 + deploy/flux-ns.yaml | 5 ++ deploy/flux-secret.yaml | 1 + deploy/kustomization.yaml | 1 + deploy/memcache-dep.yaml | 1 + deploy/memcache-svc.yaml | 1 + docs/tutorials/get-started-kustomize.md | 63 ++++++++++++++++++------- pkg/install/generate.go | 1 + 9 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 deploy/flux-ns.yaml diff --git a/deploy/flux-account.yaml b/deploy/flux-account.yaml index 4bf7702e2..12c2fd66b 100644 --- a/deploy/flux-account.yaml +++ b/deploy/flux-account.yaml @@ -7,6 +7,7 @@ metadata: labels: name: flux name: flux + namespace: flux --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRole @@ -34,4 +35,4 @@ roleRef: subjects: - kind: ServiceAccount name: flux - namespace: default + namespace: flux diff --git a/deploy/flux-deployment.yaml b/deploy/flux-deployment.yaml index 519a4879e..dfb01ab07 100644 --- a/deploy/flux-deployment.yaml +++ b/deploy/flux-deployment.yaml @@ -3,6 +3,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: flux + namespace: flux spec: replicas: 1 selector: diff --git a/deploy/flux-ns.yaml b/deploy/flux-ns.yaml new file mode 100644 index 000000000..96c664b0d --- /dev/null +++ b/deploy/flux-ns.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: flux diff --git a/deploy/flux-secret.yaml b/deploy/flux-secret.yaml index f3c110ebf..dde0d9cef 100644 --- a/deploy/flux-secret.yaml +++ b/deploy/flux-secret.yaml @@ -3,4 +3,5 @@ apiVersion: v1 kind: Secret metadata: name: flux-git-deploy + namespace: flux type: Opaque diff --git a/deploy/kustomization.yaml b/deploy/kustomization.yaml index a0b955185..3721bae3c 100644 --- a/deploy/kustomization.yaml +++ b/deploy/kustomization.yaml @@ -1,4 +1,5 @@ resources: + - flux-ns.yaml - memcache-svc.yaml - memcache-dep.yaml - flux-account.yaml diff --git a/deploy/memcache-dep.yaml b/deploy/memcache-dep.yaml index 1e0728bc7..e38b592d2 100644 --- a/deploy/memcache-dep.yaml +++ b/deploy/memcache-dep.yaml @@ -5,6 +5,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: memcached + namespace: flux spec: replicas: 1 selector: diff --git a/deploy/memcache-svc.yaml b/deploy/memcache-svc.yaml index ab01cf718..37da85667 100644 --- a/deploy/memcache-svc.yaml +++ b/deploy/memcache-svc.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: Service metadata: name: memcached + namespace: flux spec: ports: - name: memcached diff --git a/docs/tutorials/get-started-kustomize.md b/docs/tutorials/get-started-kustomize.md index f333bf637..104a00769 100644 --- a/docs/tutorials/get-started-kustomize.md +++ b/docs/tutorials/get-started-kustomize.md @@ -24,28 +24,14 @@ First you'll need a git repository to store your cluster desired state. In our example we are going to use [`fluxcd/flux-get-started`](https://github.com/fluxcd/flux-get-started). If you want to use that too, be sure to create a fork of it on GitHub. -Create a directory and add the `flux` namespace definition to it: - -```sh -mkdir fluxcd - -cat > fluxcd/namespace.yaml < fluxcd/kustomization.yaml < fluxcd/namespace.yaml < +EOF +``` + +Create a patch to remove the default namespace from the base: + +```sh +cat > fluxcd/patch-default-ns.yaml < +resources: + - namespace.yaml +bases: + - github.com/fluxcd/flux//deploy +patchesStrategicMerge: + - patch-default-ns.yaml + - patch.yaml +``` + ## Install Flux with Kustomize In the next step, deploy Flux to the cluster (you'll need kubectl **1.14** or newer): diff --git a/pkg/install/generate.go b/pkg/install/generate.go index 0a164a1d7..a57aa61bf 100644 --- a/pkg/install/generate.go +++ b/pkg/install/generate.go @@ -40,6 +40,7 @@ func main() { params := install.TemplateParameters{ GitURL: "git@github.com:fluxcd/flux-get-started", GitBranch: "master", + Namespace: "flux", } manifests, err := install.FillInTemplates(params) if err != nil {