Skip to content

Latest commit

 

History

History
90 lines (68 loc) · 1.77 KB

02-Reorganizing-Code-with-Kustomize-Overlays.md

File metadata and controls

90 lines (68 loc) · 1.77 KB

Reorganizing Code with Kustomize Overlays

The changes required to implement Kustomize and Kustomizations happen in the instavote application repository:

cd instavote

Re-structure your application deployment

Apply changes to the vote application

cd deploy/vote
mkdir base
git mv deployment.yaml service.yaml base/

Generate Kustomization

Install kustomize

# Install via Sourcecode
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" |bash

# Install via brew
brew install kustomize

Generate a Kustomization

cd base
kustomize create --autodetect
# A new file kustomization.yaml shall be created
cat kustomization.yaml

Generate an Overlay for the dev environment

cd ..
mkdir -p dev && cd dev
# Create a new overlay from the base '../base".

kustomize create --resources ../base
## Add the patchesStrategicMerge property
cat >> kustomization.yaml << EOF

patchesStrategicMerge:
- deployment.yaml
EOF

# Generate the patch
cat >> deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: vote
  name: vote
spec:
  replicas: 1
  template:
    spec:
      containers:
      - image: schoolofdevops/vote:v5
        name: vote
EOF

Verify the kustomize construction

Kustomize construcs its output based in the structure declared at kustomize.yaml. We can render its preview by executing:

kustomize build

Push your changes to the remote so Flux can reconcile its components

git add -v deploy/
git commit -m "refactor: Introduce Kustomizations for vote/dev application"
git push origin HEAD:refs/heads/main

Next: Deploying to Dev with Custom Configurations