Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Created October 3, 2021 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vfarcic/17c8eccc00dc4c76d618ec4472aae5fe to your computer and use it in GitHub Desktop.
Save vfarcic/17c8eccc00dc4c76d618ec4472aae5fe to your computer and use it in GitHub Desktop.
#############################################################
# Teleporting And Interceptiong Microservices With CodeZero #
# https://youtu.be/bt5lQqRJxlE #
#############################################################
# Referenced videos:
# - How to run local multi-node Kubernetes clusters using kind: https://youtu.be/C0v5gJSWuSo
######################################
# Installing and setting up CodeZero #
######################################
git clone https://github.com/vfarcic/code-zero-demo2
cd code-zero-demo2
# Please watch https://youtu.be/C0v5gJSWuSo if you are not familiar with KinD
# Feel free to use any other Kubernetes platform
kind create cluster --config kind.yaml
npm install -g @c6o/cli
# NPM?
# Compile it to binaries and allow me to either download them or install them throuw `brew`, `chocolatey`, etc.
# I do not want to install npm for one CLI, Python 2 for another, Python 3, Go, Java, etc.
# Learn go if you're creating CLIs.
# It takes ages to install the CLI.
# added 922 packages from 680 contributors in 2+min
sudo czctl init
# The CLI requires sudo access to modify your system's hosts file.
# The hosts file is used to define in-cluster DNS information on your local machine during a teleport session.
##################################
# The problem with microservices #
##################################
kubectl apply \
--kustomize kustomize/overlays/staging
kubectl --namespace staging get all
##################################
# Teleporting into microservices #
##################################
czctl deployment teleport silly-demo \
--namespace staging
curl http://silly-demo:8080
curl http://silly-demo.staging:8080
cat /etc/hosts
kubectl apply --kustomize kustomize/base
czctl deployment teleport silly-demo \
--namespace default
##############################
# Intercepting microservices #
##############################
# In a second terminal and in the same directory
VERSION=1.0.1 PORT=8081 go run main.go
kubectl --namespace staging \
run curl \
--image alpine -it --rm -- sh -c \
"apk add -U curl && curl http://silly-demo:8080"
czctl service intercept \
--namespace staging silly-demo \
--localPort 8081 \
--remotePort 8080 \
--header silly:demo
kubectl --namespace staging \
run curl \
--image alpine -it --rm -- sh -c \
"apk add -U curl && curl http://silly-demo:8080"
kubectl --namespace staging \
run curl \
--image alpine -it --rm -- sh -c \
"apk add -U curl && curl http://silly-demo:8080 -H silly:demo"
kubectl --namespace staging get pods
# In the second terminal
# Press `ctrl+c`
#############################
# Closing CodeZero sessions #
#############################
czctl session close --all
cat /etc/hosts
###########
# Destroy #
###########
kind delete cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment