diff --git a/component-complex/base/deployment.yaml b/component-complex/base/deployment.yaml new file mode 100644 index 0000000..e7935b5 --- /dev/null +++ b/component-complex/base/deployment.yaml @@ -0,0 +1,27 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + role: app + # Track distinguishes between normal 'stable' deployment and 'canary' deployment. + # https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/#canary-deployments + track: stable +spec: + replicas: 2 + selector: + matchLabels: + role: app + track: stable + template: + metadata: + labels: + role: app + track: stable + spec: + containers: + - name: app + image: nginx:latest + envFrom: + - configMapRef: + name: app diff --git a/component-complex/base/kustomization.yaml b/component-complex/base/kustomization.yaml new file mode 100644 index 0000000..32c14f5 --- /dev/null +++ b/component-complex/base/kustomization.yaml @@ -0,0 +1,7 @@ +resources: + - deployment.yaml + +configMapGenerator: + - name: app + literals: + - downstreamServiceUrl=http://www.google.com \ No newline at end of file diff --git a/component-complex/overlays/ci/kustomization.yaml b/component-complex/overlays/ci/kustomization.yaml new file mode 100644 index 0000000..0a40491 --- /dev/null +++ b/component-complex/overlays/ci/kustomization.yaml @@ -0,0 +1,8 @@ +# ci environment needs a stub server but no ingresses (only accessible internally) +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base +components: + - ../../patches/stub +namespace: ci diff --git a/component-complex/overlays/demo-canary/kustomization.yaml b/component-complex/overlays/demo-canary/kustomization.yaml new file mode 100644 index 0000000..11bfeed --- /dev/null +++ b/component-complex/overlays/demo-canary/kustomization.yaml @@ -0,0 +1,8 @@ +# demo-canary environment is the same as demo, but configured for the canary deployment +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../demo + +components: + - ../../patches/canary diff --git a/component-complex/overlays/demo/kustomization.yaml b/component-complex/overlays/demo/kustomization.yaml new file mode 100644 index 0000000..b7ecf17 --- /dev/null +++ b/component-complex/overlays/demo/kustomization.yaml @@ -0,0 +1,11 @@ +# demo environment needs a stub server and ingresses for app and stub +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base + +components: + - ../../patches/ingress-vars + - ../../patches/stub-ingress + - ../../patches/app-ingress +namespace: demo \ No newline at end of file diff --git a/component-complex/overlays/prod-canary/kustomization.yaml b/component-complex/overlays/prod-canary/kustomization.yaml new file mode 100644 index 0000000..9e180fc --- /dev/null +++ b/component-complex/overlays/prod-canary/kustomization.yaml @@ -0,0 +1,8 @@ +# prod-canary environment is the same as prod, but configured for the canary deployment +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../prod + +components: + - ../../patches/canary diff --git a/component-complex/overlays/prod/kustomization.yaml b/component-complex/overlays/prod/kustomization.yaml new file mode 100644 index 0000000..a951c82 --- /dev/null +++ b/component-complex/overlays/prod/kustomization.yaml @@ -0,0 +1,10 @@ +# prod environment needs an app ingress and no stub +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base + +components: + - ../../patches/ingress-vars + - ../../patches/app-ingress +namespace: prod \ No newline at end of file diff --git a/component-complex/patches/app-ingress/app-ingress.yaml b/component-complex/patches/app-ingress/app-ingress.yaml new file mode 100644 index 0000000..8c3987d --- /dev/null +++ b/component-complex/patches/app-ingress/app-ingress.yaml @@ -0,0 +1,13 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: app +spec: + rules: + - host: app.$(NAMESPACE).tld + http: + paths: + - path: + backend: + serviceName: app + servicePort: http diff --git a/component-complex/patches/app-ingress/kustomization.yaml b/component-complex/patches/app-ingress/kustomization.yaml new file mode 100644 index 0000000..e22f9d2 --- /dev/null +++ b/component-complex/patches/app-ingress/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component +resources: + - app-ingress.yaml diff --git a/component-complex/patches/canary/kustomization.yaml b/component-complex/patches/canary/kustomization.yaml new file mode 100644 index 0000000..51664c2 --- /dev/null +++ b/component-complex/patches/canary/kustomization.yaml @@ -0,0 +1,30 @@ +# https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/#canary-deployments +# https://medium.com/google-cloud/kubernetes-canary-deployments-for-mere-mortals-13728ce032fe +# https://dev.to/mostlyjason/intro-to-deployment-strategies-blue-green-canary-and-more-3a3 +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component + +replicas: + - name: app-canary + count: 1 + +patches: + - patch: |- + # Need to change the deployment name so that the original app deployment still runs (with the old version) + - op: replace + path: /metadata/name + value: app-canary + # Need to change these so that the deployment can link to its pods correctly + # https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#selector + - op: replace + path: /metadata/labels/track + value: canary + - op: replace + path: /spec/selector/matchLabels/track + value: canary + - op: replace + path: /spec/template/metadata/labels/track + value: canary + target: + kind: Deployment + name: app \ No newline at end of file diff --git a/component-complex/patches/ingress-vars/kustomization.yaml b/component-complex/patches/ingress-vars/kustomization.yaml new file mode 100644 index 0000000..31ddad1 --- /dev/null +++ b/component-complex/patches/ingress-vars/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component +vars: + - name: NAMESPACE + objref: + apiVersion: apps/v1 + kind: Deployment + name: app + fieldref: + fieldpath: metadata.namespace + +configurations: + - kustomize-configuration.yaml \ No newline at end of file diff --git a/component-complex/patches/ingress-vars/kustomize-configuration.yaml b/component-complex/patches/ingress-vars/kustomize-configuration.yaml new file mode 100644 index 0000000..70e2604 --- /dev/null +++ b/component-complex/patches/ingress-vars/kustomize-configuration.yaml @@ -0,0 +1,4 @@ +# Additional locations where variables can be interpolated +varReference: + - path: spec/rules/host + kind: Ingress diff --git a/component-complex/patches/stub-ingress/kustomization.yaml b/component-complex/patches/stub-ingress/kustomization.yaml new file mode 100644 index 0000000..175d376 --- /dev/null +++ b/component-complex/patches/stub-ingress/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component +resources: + - ../stub + - stub-ingress.yaml diff --git a/component-complex/patches/stub-ingress/kustomize-configuration.yaml b/component-complex/patches/stub-ingress/kustomize-configuration.yaml new file mode 100644 index 0000000..70e2604 --- /dev/null +++ b/component-complex/patches/stub-ingress/kustomize-configuration.yaml @@ -0,0 +1,4 @@ +# Additional locations where variables can be interpolated +varReference: + - path: spec/rules/host + kind: Ingress diff --git a/component-complex/patches/stub-ingress/stub-ingress.yaml b/component-complex/patches/stub-ingress/stub-ingress.yaml new file mode 100644 index 0000000..ac9dd0b --- /dev/null +++ b/component-complex/patches/stub-ingress/stub-ingress.yaml @@ -0,0 +1,13 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: stub +spec: + rules: + - host: stub.$(NAMESPACE).tld + http: + paths: + - path: + backend: + serviceName: stub + servicePort: http diff --git a/component-complex/patches/stub/kustomization.yaml b/component-complex/patches/stub/kustomization.yaml new file mode 100644 index 0000000..d51750b --- /dev/null +++ b/component-complex/patches/stub/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component +resources: + - stub-service.yaml + - stub-deployment.yaml + +configMapGenerator: + - name: app + behavior: merge + literals: + - downstreamServiceUrl=http://stub:9080 diff --git a/component-complex/patches/stub/stub-deployment.yaml b/component-complex/patches/stub/stub-deployment.yaml new file mode 100644 index 0000000..7c42f11 --- /dev/null +++ b/component-complex/patches/stub/stub-deployment.yaml @@ -0,0 +1,10 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: stub +spec: + template: + spec: + containers: + - name: stub + image: nginx:latest diff --git a/component-complex/patches/stub/stub-service.yaml b/component-complex/patches/stub/stub-service.yaml new file mode 100644 index 0000000..e804f06 --- /dev/null +++ b/component-complex/patches/stub/stub-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: stub +spec: + type: ClusterIP + selector: + role: stub + ports: + - name: http + port: 9080 + protocol: TCP diff --git a/component/base/deployment.yaml b/component/base/deployment.yaml new file mode 100644 index 0000000..7958f19 --- /dev/null +++ b/component/base/deployment.yaml @@ -0,0 +1,10 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: my-deployment +spec: + template: + spec: + containers: + - name: my-deployment + image: my-image diff --git a/component/base/kustomization.yaml b/component/base/kustomization.yaml new file mode 100644 index 0000000..c941c1f --- /dev/null +++ b/component/base/kustomization.yaml @@ -0,0 +1,9 @@ +resources: + - deployment.yaml + +configMapGenerator: + - name: app-config + literals: + - testValue1=from-base + - testValue2=from-base + - otherValue=from-base \ No newline at end of file diff --git a/component/overlays/aggregate/kustomization.yaml b/component/overlays/aggregate/kustomization.yaml new file mode 100644 index 0000000..58068ee --- /dev/null +++ b/component/overlays/aggregate/kustomization.yaml @@ -0,0 +1,9 @@ +kind: Kustomization +apiVersion: kustomize.config.k8s.io/v1beta1 + +resources: + - ../../base + +components: + - ../../patches/patch1 + - ../../patches/patch2 diff --git a/component/patches/patch1/kustomization.yaml b/component/patches/patch1/kustomization.yaml new file mode 100644 index 0000000..dfe35d0 --- /dev/null +++ b/component/patches/patch1/kustomization.yaml @@ -0,0 +1,12 @@ +kind: Component +apiVersion: kustomize.config.k8s.io/v1alpha1 + +patchesStrategicMerge: + - patches/patch.yaml + +configMapGenerator: + - name: app-config + behavior: merge + literals: + - testValue1=from-patch1 + - patchValue=from-patch1 \ No newline at end of file diff --git a/component/patches/patch1/patches/patch.yaml b/component/patches/patch1/patches/patch.yaml new file mode 100644 index 0000000..848ee17 --- /dev/null +++ b/component/patches/patch1/patches/patch.yaml @@ -0,0 +1,6 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: my-deployment +spec: + replicas: 2 diff --git a/component/patches/patch2/kustomization.yaml b/component/patches/patch2/kustomization.yaml new file mode 100644 index 0000000..6091daa --- /dev/null +++ b/component/patches/patch2/kustomization.yaml @@ -0,0 +1,12 @@ +kind: Component +apiVersion: kustomize.config.k8s.io/v1alpha1 + +patchesStrategicMerge: + - patches/patch.yaml + +configMapGenerator: + - name: app-config + behavior: merge + literals: + - testValue2=from-patch2 + - patchValue=from-patch2 \ No newline at end of file diff --git a/component/patches/patch2/patches/patch.yaml b/component/patches/patch2/patches/patch.yaml new file mode 100644 index 0000000..950f612 --- /dev/null +++ b/component/patches/patch2/patches/patch.yaml @@ -0,0 +1,9 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: my-deployment +spec: + template: + metadata: + labels: + app: my-app