Skip to content

Instantly share code, notes, and snippets.

@gregoryg
Created November 22, 2019 20:51
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 gregoryg/a13068e442d467c98f84039c6eb272d9 to your computer and use it in GitHub Desktop.
Save gregoryg/a13068e442d467c98f84039c6eb272d9 to your computer and use it in GitHub Desktop.
Sequence to use for a KUDO Meetup

kudo-cheatsheet

1 KUDO Demo sheet

This demo sheet was originally cloned from Nick Jones’ demo.org gist

1.1 Set up shell for for demo

(shell "konvoy-sh")
(switch-to-buffer "kudo-demo-sheet.org")
(delete-other-windows  )
(switch-to-buffer-other-window "konvoy-sh")
;;(switch-to-buffer "kudo-cheatsheet.org")

1.2 Show state of cluster prior to KUDO

Note there is no operators or api-resources resource type

kubectl get crds
kubectl get pods
kubectl get operators
kubectl api-resources

1.3 Install KUDO CLI kubectl-kudo

Look at https://github.com/kudobuilder/kudo/releases

TODO: get latest release, install

1.4 Install KUDO

This is pure kubernetes - installs prerequisites with custom resource definitions (CRD)

If you’re using the new KUDO CLI which has this commit (v0.6.0 or later) then you can do:

kubectl kudo init

Otherwise:

kubectl create -f https://raw.githubusercontent.com/kudobuilder/kudo/v0.5.0/docs/deployment/00-prereqs.yaml
kubectl create -f https://raw.githubusercontent.com/kudobuilder/kudo/v0.5.0/docs/deployment/10-crds.yaml
kubectl create -f https://raw.githubusercontent.com/kudobuilder/kudo/v0.5.0/docs/deployment/20-deployment.yaml

1.5 Show state of cluster after installing KUDO

kubectl get crds | grep kudo
kubectl api-resources --api-group kudo.dev

2 Examples of KUDO operators

2.1 Zookeeper

kubectl kudo install zookeeper --instance zk
kubectl kudo plan status --instance zk
kubectl get pods -w
# mype=$(kubectl get planexecutions | grep 'zk-deploy-' | cut -d' ' -f1)
# kubectl get planexecutions
# kubectl describe planexecution ${mype}
# EDITOR=emacsclient kubectl edit planexecution ${mype}

kubectl kudo get instances
kubectl kudo plan status --instance zk
kubectl get statefulset zk-zookeeper
EDITOR=emacsclient kubectl edit statefulset zk-zookeeper
kubectl get operators
kubectl get operatorversions
kubectl describe operatorversion zookeeper-0.2.0
EDITOR=emacsclient kubectl edit operatorversion zookeeper-0.2.0

2.2 Kafka

2.2.1 Install Kafka

# cd ~/projects/mesosphere/kudo/operators/repository/kafka/operator/
# kubectl kudo install . --instance kafka

kubectl kudo install kafka --instance=kafka \
		-p ZOOKEEPER_URI=zk-zookeeper-0.zk-hs:2181,zk-zookeeper-1.zk-hs:2181,zk-zookeeper-2.zk-hs:2181 \
		-p BROKER_MEM=1024m \
		--version=0.1.3
# kubectl kudo install kafka --instance=kafka -p BROKER_MEM=1024m
kubectl kudo plan status --instance=kafka
kubectl get instances
kubectl get operators
kubectl get operatorversions
kubectl describe operatorversions kafka-1.0.1 | tee /tmp/kafka-1.0.1.yaml
EDITOR=emacsclient kubectl edit operatorversions kafka-0.2.0
kubectl get configmaps
EDITOR=emacsclient kubectl edit configmaps
kubectl kudo plan status --instance=kafka

2.2.2 Show instance, plan status, service networking

kubectl describe instance kafka
kubectl kudo plan status --instance kafka
kubectl get pods -w
kubectl logs kafka-kafka-0 | grep 'Kafka version'
kubectl get svc
kubectl run -it --image=busybox --restart=Never sh
wget -O - kafka-svc:9094
kubectl delete pod sh

2.2.3 Install Prometheus monitoring on non-Konvoy clusters

Konvoy will already have this set up

# From a clone of the Prometheus Operator: https://github.com/coreos/kube-prometheus
kubectl apply -f manifests/
# Once everything is running
kubectl --namespace monitoring port-forward svc/grafana 3000
# Add the Kafka service monitor definition from the kudo-kafka-demo repo
kubectl apply -f service-monitor.yml
# Browse to localhost:3000 and load the dashboard from https://raw.githubusercontent.com/kudobuilder/operators/master/repository/kafka/docs/v0.1/resources/grafana-dashboard.json

2.2.4 Enable Kafka metrics export

Run the following command to enable Kafka metrics export:

kubectl create -f https://raw.githubusercontent.com/kudobuilder/operators/master/repository/kafka/docs/v0.2/resources/service-monitor.yaml

2.2.5 Generate load

From a checkout of the KUDO Kafka demo: https://github.com/zmalik/kudo-kafka-demo

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: kudo-kafka-generator
spec:
  replicas: 1
  template:
    metadata:
      name: kudo-kafka-generator
      labels:
        app: kudo-kafka-generator
    spec:
      containers:
      - name: kudo-kafka-generator
        image: mesosphere/flink-generator:0.1
        command: ["/generator-linux"]
        imagePullPolicy: Always
        args: ["--broker", "kafka-kafka-0.kafka-svc:9092"]
kubectl apply -f /tmp/kafka-producer-generator.yaml
kubectl get pods
mypod=$(kubectl get pods | grep 'kudo-kafka-generator' | cut -d' ' -f1)
kubectl logs -f ${mypod}
kubectl get deployments

2.2.6 Kafka consumer

Consume the messages being generated on the Kafka topic

apiVersion: apps/v1beta1
kind: Deployment
metadata:
 name: kudo-kafka-consumer
spec:
 replicas: 1
 template:
   metadata:
     name: kudo-kafka-consumer
     labels:
       app: kudo-kafka-consumer
   spec:
     containers:
     - name: kudo-kafka-consumer
       image: tbaums/kudo-kafka-demo
       imagePullPolicy: Always
       env:
        - name: BROKER_SERVICE
          value: kafka-kafka-0.kafka-svc:9092
kubectl apply -f /tmp/kafka-consumer.yaml
kubectl get pods
mypod=$(kubectl get pods | grep 'kudo-kafka-consumer' | cut -d' ' -f1)
kubectl logs -f ${mypod}
kubectl get deployments

2.2.8 Upgrade Kafka to 2.3.0

Upgrade your Kafka cluster to 2.3.0 (the version of the KUDO Kafka operator is 1.0.0) using the following command:

kubectl kudo upgrade kafka --version=1.0.0 --instance kafka

2.2.9 Update using CI/CD

kubectl kudo update --instance kafka -p BROKER_MEM=2048Mi -p BROKER_COUNT=5

2.2.9.1 Further prove it’s a real Kafka cluster

kubectl describe svc kafka-svc
kubectl get svc
kubectl describe svc kafka-svc
kubectl run -it --image=busybox --restart=Never sh
wget -O - kafka-svc:9094/metrics

2.3 MySQL

2.3.1 Install

# cd ~/projects/mesosphere/kudo/operators/repository/mysql/operator/
# kubectl kudo install . --instance mysql
kubectl kudo install mysql --instance mysql
kubectl get pods -l app=mysql -o jsonpath="{.items[*].metadata.name}" ; echo
export MYSQL_POD=$(kubectl get pods -l app=mysql -o jsonpath="{.items[*].metadata.name}")
echo $MYSQL_POD

2.3.2 Create table and populate some data

MYSQL_POD=`kubectl get pods -l app=mysql -o jsonpath="{.items[*].metadata.name}"`
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "create database kudo;" 
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "create table example (id INT, name varchar(25));" kudo
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "show tables;" kudo
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "INSERT INTO example ( id, name ) VALUES ( null, 'New Data' );" kudo
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "INSERT INTO example ( id, name ) VALUES ( null, 'New Data' );" kudo
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "INSERT INTO example ( id, name ) VALUES ( null, 'New Data' );" kudo
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "INSERT INTO example ( id, name ) VALUES ( null, 'New Data' );" kudo
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "select * from example;" kudo

2.3.3 Backup

cat << EOF | kubectl apply -f -
apiVersion: kudo.dev/v1alpha1
kind: PlanExecution
metadata:
  labels:
    framework-version: mysql-57
    instance: mysql
  name: mysql-backup
  namespace: default
spec:
  instance:
    kind: Instance
    name: mysql
    namespace: default
  planName: backup
EOF
kubectl kudo plan status --instance mysql

2.3.4 Delete data

kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "delete from example;" kudo
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "select * from example;" kudo

2.3.5 Restore

cat << EOF | kubectl apply -f -
apiVersion: kudo.dev/v1alpha1
kind: PlanExecution
metadata:
  labels:
    framework-version: mysql-57
    instance: mysql
  name: mysql-restore
  namespace: default
spec:
  instance:
    kind: Instance
    name: mysql
    namespace: default
  planName: restore
EOF
kubectl kudo plan status --instance mysql
kubectl exec -it $MYSQL_POD -- mysql -ppassword  -e "select * from example;" kudo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment