Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Last active June 13, 2023 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vfarcic/93b1060b77f7ccacf422192c73e7bf24 to your computer and use it in GitHub Desktop.
Save vfarcic/93b1060b77f7ccacf422192c73e7bf24 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/93b1060b77f7ccacf422192c73e7bf24
##########################################################################
# Kubernetes Observability And Troubleshooting With groundcover and eBPF #
# https://youtu.be/2pwgbeY7wmY #
##########################################################################
# Additional Info:
# - groundcover: https://groundcover.com
# - Is eBPF The End Of Kubernetes Sidecar Containers?: https://youtu.be/7ZVQSg9HX68
# - The Best Performance And Load Testing Tool? k6 By Grafana Labs: https://youtu.be/5OgQuVAR14I
#########
# Setup #
#########
# Create a Kubernetes cluster.
# See https://docs.groundcover.com/docs/install-groundcover/requirements#environments
# for the list of supported clusters.
# Do not use a local Kubernetes cluster (e.g., Rancher Desktop)
# since some of the Groundcover features might not work.
helm repo add traefik https://helm.traefik.io/traefik
helm repo update
helm upgrade --install traefik traefik/traefik \
--namespace traefik --create-namespace --wait
# If NOT EKS
export INGRESS_HOST=$(kubectl --namespace traefik \
get service traefik \
--output jsonpath="{.status.loadBalancer.ingress[0].ip}")
# If EKS
export INGRESS_HOSTNAME=$(kubectl --namespace traefik \
get service traefik \
--output jsonpath="{.status.loadBalancer.ingress[0].hostname}")
# If EKS
export INGRESS_HOST=$(dig +short $INGRESS_HOSTNAME)
echo $INGRESS_HOST
# Repeat the `export` commands if the output is empty.
# If the output contains more than one IP, wait for a while
# longer, and repeat the `export` commands.
# If the output continues having more than one IP, choose one of
# them and execute `export INGRESS_HOST=[...]` with `[...]`
# being the selected IP.
git clone https://github.com/vfarcic/groundcover-demo
cd groundcover-demo
# Install `yq` from https://github.com/mikefarah/yq if you do not have it already
yq --inplace \
".spec.rules[0].host = \"silly-demo.$INGRESS_HOST.nip.io\"" \
k8s/ing.yaml
cat k6.js \
| sed -e "s@http\.get.*@http\.get('http://silly-demo.$INGRESS_HOST.nip.io');@" \
| tee k6.js
cat k6-db.js \
| sed -e "s@http\.get.*@http\.get('http://silly-demo.$INGRESS_HOST.nip.io/video?id=something\&title=else');@" \
| tee k6-db.js
sh -c "$(curl -fsSL https://groundcover.com/install.sh)"
groundcover auth login
groundcover deploy --yes
kubectl create namespace production
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
########################
# groundcover Hands-On #
########################
kubectl --namespace groundcover get pods
kubectl --namespace production apply --filename k8s
# Open https://app.groundcover.com in a browser
# Namespace > production
# TODO: Neither the app nor the Namespace is there
kubectl --namespace production get pods
helm upgrade --install postgresql bitnami/postgresql \
--namespace production --wait
export POSTGRES_PASSWORD_ENCODED=$(kubectl \
--namespace production get secret postgresql \
--output jsonpath="{.data.postgres-password}"
)
export POSTGRES_PASSWORD=$(echo $POSTGRES_PASSWORD_ENCODED \
| base64 --decode
)
echo "
apiVersion: v1
kind: Secret
metadata:
name: silly-demo
data:
endpoint: cG9zdGdyZXNxbAo=
port: NTQzMgo=
username: cG9zdGdyZXMK
password: $POSTGRES_PASSWORD_ENCODED
type: Opaque
" | kubectl --namespace production apply --filename -
kubectl --namespace production get pods
curl -X POST "http://silly-demo.$INGRESS_HOST.nip.io/video?id=wNBG1-PSYmE&title=Kubernetes%20Policies%20And%20Governance%20-%20Ask%20Me%20Anything%20With%20Jim%20Bugwadia"
kubectl --namespace production run postgresql-client \
--rm --tty -i --rm --restart='Never' \
--image docker.io/bitnami/postgresql:15.0.0-debian-11-r3 \
--env="PGPASSWORD=$POSTGRES_PASSWORD" \
--command -- psql --host postgresql -U postgres -p 5432
CREATE DATABASE "silly-demo";
\c "silly-demo"
CREATE TABLE videos (
id text PRIMARY KEY,
title text
);
exit
curl -X POST "http://silly-demo.$INGRESS_HOST.nip.io/video?id=wNBG1-PSYmE&title=Kubernetes%20Policies%20And%20Governance%20-%20Ask%20Me%20Anything%20With%20Jim%20Bugwadia"
curl -X POST "http://silly-demo.$INGRESS_HOST.nip.io/video?id=VlBiLFaSi7Y&title=Scaleway%20-%20Everything%20We%20Expect%20From%20A%20Cloud%20Computing%20Service%3F"
curl -X POST "http://silly-demo.$INGRESS_HOST.nip.io/video?id=VlBiLFaSi7Y&title=Scaleway%20-%20Everything%20We%20Expect%20From%20A%20Cloud%20Computing%20Service%3F"
curl "http://silly-demo.$INGRESS_HOST.nip.io/videos" | jq .
k6 run k6.js
k6 run k6-db.js
###########
# Destroy #
###########
# Reset of destroy the cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment