Skip to content

Instantly share code, notes, and snippets.

@oleoneto
Forked from vfarcic/189-metacontroller.sh
Created December 6, 2022 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oleoneto/3cabd590fbcbb9076fef796e1f9f7499 to your computer and use it in GitHub Desktop.
Save oleoneto/3cabd590fbcbb9076fef796e1f9f7499 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/8adaf8fd6496bc99a466ba55834e1838
###############################################################
# Metacontroller - Custom Kubernetes Controllers The Easy Way #
# https://youtu.be/3xkLYOpXy2U #
###############################################################
# Additional Info:
# - Metacontroller: https://metacontroller.github.io/metacontroller
# - DevOps MUST Build Internal Developer Platform (IDP): https://youtu.be/j5i00z3QXyU
# - Crossplane - GitOps-based Infrastructure as Code through Kubernetes API: https://youtu.be/n8KjVmuHm7A
# - Terraform vs. Pulumi vs. Crossplane - Infrastructure as Code (IaC) Tools Comparison: https://youtu.be/RaoKcJGchKM
# - How To Apply GitOps To Everything - Combining Argo CD And Crossplane: https://youtu.be/yrj4lmScKHQ
# - How To Shift Left Infrastructure Management Using Crossplane Compositions: https://youtu.be/AtbS1u2j7po
# - Cloud-Native Apps With Open Application Model (OAM) And KubeVela: https://youtu.be/2CBu6sOTtwk
# - Combining Argo CD (GitOps), Crossplane (Control Plane), And KubeVela (OAM): https://youtu.be/eEcgn_gU3SM
# - Should We Replace Docker Desktop With Rancher Desktop?: https://youtu.be/bYVfCp9dRTE
#########
# Setup #
#########
git clone https://github.com/vfarcic/metacontroller-demo
cd metacontroller-demo
# Create a Kubernetes cluster with Ingress controller enabled and set as default.
# This demo was tested on Rancher Desktop, but it should work with any Kubernetes cluster
# Please watch https://youtu.be/bYVfCp9dRTE if you are not familiar with Rancher Desktop
# Replace `127.0.0.1` with the Ingress Service IP if not using kind
export INGRESS_HOST=127.0.0.1
kubectl apply \
--kustomize https://github.com/metacontroller/metacontroller/manifests/production
kubectl create namespace production
kubectl create namespace controllers
# Install `yq` from https://github.com/mikefarah/yq if you do not have it already
yq --inplace \
".spec.host = \"silly-demo.$INGRESS_HOST.nip.io\"" \
my-app.yaml
yq --inplace \
".spec.host = \"silly-demo.$INGRESS_HOST.nip.io\"" \
my-app-1-0-7.yaml
#################################################
# Kubernetes Custom Resource Definitions (CRDs) #
#################################################
cat crds.yaml
kubectl apply --filename crds.yaml
kubectl get crds
kubectl explain apps --recursive
cat slack.yaml
kubectl apply --filename slack.yaml
kubectl get slacks
cat my-app.yaml
kubectl --namespace production apply \
--filename my-app.yaml
kubectl --namespace production \
get apps
kubectl --namespace production delete \
--filename my-app.yaml
#################################
# Custom Kubernetes Controllers #
#################################
cat composite-controllers.yaml
kubectl apply \
--filename composite-controllers.yaml
kubectl get compositecontrollers
cat main.go
cat app.py
kubectl --namespace controllers \
create configmap app \
--from-file=app.py
cat controllers.yaml
kubectl --namespace controllers apply \
--filename controllers.yaml
############################
# Metacontroller In Action #
############################
cat my-app.yaml
kubectl --namespace production apply \
--filename my-app.yaml
kubectl --namespace controllers logs \
--selector app=slack-controller
kubectl --namespace production \
get apps
kubectl --namespace production \
get all,ingresses
diff my-app.yaml my-app-1-0-7.yaml
kubectl --namespace production apply \
--filename my-app-1-0-7.yaml
kubectl --namespace production \
get all,ingresses
curl "http://silly-demo.$INGRESS_HOST.nip.io"
kubectl --namespace production delete \
--filename my-app-1-0-7.yaml
kubectl --namespace production \
get all,ingresses
###########
# Destroy #
###########
# Destroy or reset the Kubernetes cluster
# ... or ...
kubectl delete \
--filename composite-controllers.yaml
kubectl delete --filename slack.yaml
kubectl delete --filename crds.yaml
kubectl delete ns controllers
kubectl delete ns metacontroller
kubectl delete ns production
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment