Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Last active September 15, 2022 03:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save vfarcic/497a72d63c159e93f7351480f7506c05 to your computer and use it in GitHub Desktop.
Save vfarcic/497a72d63c159e93f7351480f7506c05 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/497a72d63c159e93f7351480f7506c05
######################################################################
# kpt YAML Transformation - No Helm Templates, No Kustomize Overlays #
# https://youtu.be/Wavigyq7NdQ #
######################################################################
# Additional Info:
# - kpt: https://kpt.dev
# - How To Write And Test Kubernetes Manifests With Datree: https://youtu.be/3jZTqCETW2w
# - Helm vs Kustomize - The Fight Between Templating and Patching in Kubernetes: https://youtu.be/ZMFYSm0ldQ0
#########
# Setup #
#########
# Install `kpt` CLI from https://kpt.dev/installation/kpt-cli
# Install `datee` CLI from https://hub.datree.io/#1-install-the-datree-cli
# Make sure that Docker and a Kubernetes cluster are running
kubectl create namespace a-team
git clone https://github.com/vfarcic/kpt-demo
cd kpt-demo
###############
# Explore kpt #
###############
ls -1 base/
datree test base/*.yaml
cat base/*.yaml
kpt pkg tree
kpt fn eval base \
--image gcr.io/kpt-fn/set-labels:v0.1.5 \
-- app=devops-toolkit
git status
git diff base/*.yaml
git add .
git commit -m "Labels"
datree test base/*.yaml
kpt fn eval --image set-namespace:v0.1 \
-- namespace=a-team
git diff base/*.yaml
git add .
git commit -m "Namespace"
datree test base/*.yaml
cat Kptfile
kpt fn render
git diff base/*.yaml
git add .
git commit -m "Labels"
kpt live init
git diff Kptfile
kpt live apply --reconcile-timeout=15m
kubectl --namespace a-team \
get all,ingresses
kubectl --namespace a-team \
get deployment devops-toolkit \
--output yaml
# Open https://catalog.kpt.dev
# Open https://kpt.dev/gitops/configsync/
# Open https://github.com/argoproj/argo-cd/issues/3360
kpt fn source base \
| kpt fn eval - \
--image set-image:v0.1.1 \
-- \
name=vfarcic/devops-toolkit-series \
newName=vfarcic/devops-toolkit-series \
newTag=5.0.5 \
| kpt fn eval - \
--image set-namespace:v0.4.1 \
-- \
namespace=prod \
| kpt fn sink prod
kpt pkg tree
cat prod/deployment.yaml
cd ..
kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/wordpress@v0.9
cd wordpress
cat Kptfile
###########
# Destroy #
###########
cd ../kpt-demo
kpt live destroy
# Destroy or reset the Kubernetes cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment