Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions component-complex/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions component-complex/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resources:
- deployment.yaml

configMapGenerator:
- name: app
literals:
- downstreamServiceUrl=http://www.google.com
8 changes: 8 additions & 0 deletions component-complex/overlays/ci/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions component-complex/overlays/demo-canary/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions component-complex/overlays/demo/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions component-complex/overlays/prod-canary/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions component-complex/overlays/prod/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions component-complex/patches/app-ingress/app-ingress.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions component-complex/patches/app-ingress/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- app-ingress.yaml
30 changes: 30 additions & 0 deletions component-complex/patches/canary/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions component-complex/patches/ingress-vars/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Additional locations where variables can be interpolated
varReference:
- path: spec/rules/host
kind: Ingress
5 changes: 5 additions & 0 deletions component-complex/patches/stub-ingress/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- ../stub
- stub-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Additional locations where variables can be interpolated
varReference:
- path: spec/rules/host
kind: Ingress
13 changes: 13 additions & 0 deletions component-complex/patches/stub-ingress/stub-ingress.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions component-complex/patches/stub/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions component-complex/patches/stub/stub-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: stub
spec:
template:
spec:
containers:
- name: stub
image: nginx:latest
12 changes: 12 additions & 0 deletions component-complex/patches/stub/stub-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: stub
spec:
type: ClusterIP
selector:
role: stub
ports:
- name: http
port: 9080
protocol: TCP
10 changes: 10 additions & 0 deletions component/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-deployment
spec:
template:
spec:
containers:
- name: my-deployment
image: my-image
9 changes: 9 additions & 0 deletions component/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resources:
- deployment.yaml

configMapGenerator:
- name: app-config
literals:
- testValue1=from-base
- testValue2=from-base
- otherValue=from-base
9 changes: 9 additions & 0 deletions component/overlays/aggregate/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: Kustomization
apiVersion: kustomize.config.k8s.io/v1beta1

resources:
- ../../base

components:
- ../../patches/patch1
- ../../patches/patch2
12 changes: 12 additions & 0 deletions component/patches/patch1/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions component/patches/patch1/patches/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 2
12 changes: 12 additions & 0 deletions component/patches/patch2/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions component/patches/patch2/patches/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-deployment
spec:
template:
metadata:
labels:
app: my-app