Coder Social home page Coder Social logo

scripts-knative's Introduction

Scripts/Examples to compliment bit.ly/knative-tutorial

git clone critical repos

git clone https://github.com/burrsutter/scripts-knative

cd scripts-knative

Steps

Install Stuff

cd /wherever

mkdir bin

cd bin

curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.7.2/minikube-darwin-amd64

chmod +x minikube

./minikube version
minikube version: v1.7.2
commit: 50d543b5fcb0e1c0d7c27b1398a9a9790df09dfb

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/darwin/amd64/kubectl

chmod +x kubectl
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"darwin/amd64"}


curl -LO https://github.com/knative/client/releases/download/v0.12.0/kn-darwin-amd64

mv kn-darwin-amd64 kn

chmod +x kn
./kn version
Version:      v0.12.0
Build Date:   2020-01-29 21:03:45
Git Revision: 164cb5f


export PATH=/wherever/bin

Start Minikube

PROFILE_NAME=knativecookbook
MEMORY=8192
CPUS=4

EXTRA_CONFIG="apiserver.enable-admission-plugins=\
LimitRanger,\
NamespaceExists,\
NamespaceLifecycle,\
ResourceQuota,\
ServiceAccount,\
DefaultStorageClass,\
MutatingAdmissionWebhook"

minikube profile $PROFILE_NAME
minikube start --memory=$MEMORY --cpus=$CPUS \
  --kubernetes-version=v1.15.0 \
  --disk-size=50g \
  --extra-config="$EXTRA_CONFIG" \
  --insecure-registry='10.0.0.0/24'

Install Knative

kubectl apply --selector knative.dev/crd-install=true \
  --filename https://github.com/knative/serving/releases/download/v0.12.0/serving-crds.yaml \
  --filename https://github.com/knative/eventing/releases/download/v0.12.0/eventing.yaml

kubectl apply \
  --filename \
  https://github.com/knative/serving/releases/download/v0.12.0/serving-core.yaml

watch kubectl get pods -n knative-serving

kubectl apply \
  --filename \
 https://raw.githubusercontent.com/knative/serving/v0.12.0/third_party/kourier-latest/kourier.yaml

watch kubectl get pods -n kourier-system

kubectl patch configmap/config-network \
  -n knative-serving \
  --type merge \
  -p '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'

kubectl apply \
  --selector \
  networking.knative.dev/certificate-provider!=cert-manager \
  --filename \
  https://github.com/knative/eventing/releases/download/v0.12.0/eventing.yaml

watch kubectl get pods -n knative-eventing

Deploy First Knative Service

kubectl create namespace knativetutorial

kubectl config set-context --current --namespace=knativetutorial

git clone https://github.com/redhat-developer-demos/knative-tutorial

git checkout knative-cookbook

cd basics

watch kubectl get pods

kubectl apply -n knativetutorial -f service.yaml

kubectl get ksvc

kubectl get deployments -n knativetutorial

kubectl get revisions

kubectl --namespace knativetutorial get rev \
--selector=serving.knative.dev/service=greeter \
--sort-by="{.metadata.creationTimestamp}"


kubectl get configurations

kubectl get routes


IP_ADDRESS="$(minikube ip):$(kubectl get svc kourier-external --namespace kourier-system --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')"

http $IP_ADDRESS 'Host:greeter.knativetutorial.example.com'

# OR

curl -H "Host:greeter.knativetutorial.example.com" $IP_ADDRESS

Deploy 2nd Revision

kubectl apply -n knativetutorial -f service-env.yaml

kubectl get ksvc


kubectl --namespace knativetutorial get rev \
--selector=serving.knative.dev/service=greeter \
--sort-by="{.metadata.creationTimestamp}"

kubectl get deployments

curl -H "Host:greeter.knativetutorial.example.com" $IP_ADDRESS

Shift Traffic

kn service update greeter --traffic greeter-v1=100,greeter-v2=0

curl -H "Host:greeter.knativetutorial.example.com" $IP_ADDRESS

kn service update greeter --traffic greeter-v1=0,greeter-v2=100

curl -H "Host:greeter.knativetutorial.example.com" $IP_ADDRESS

kn cli

kn version

# create a Knative Service, no YAML

kn service create greeter --namespace knativetutorial --image quay.io/rhdevelopers/knative-tutorial-greeter:quarkus

kn service list

IP_ADDRESS="$(minikube ip):$(kubectl get svc kourier-external --namespace kourier-system --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')"

http $IP_ADDRESS 'Host:greeter.knativetutorial.example.com'

kn service delete greeter

Knative Scaling

cd scaling

kubectl apply -f service-10.yaml

kubectl get ksvc

curl -H "Host:prime-generator.knativetutorial.example.com" $IP_ADDRESS

curl -H "Host:prime-generator.knativetutorial.example.com" $IP_ADDRESS/?sleep=3&upto=10000&memload=100

brew install hey

hey -c 50 -z 10s \
  -H "Host:prime-generator.knativetutorial.example.com" \
  "http://${IP_ADDRESS}/?sleep=3&upto=10000&memload=100"

siege -r 1 -c 30 -d 2 -v -H "Host:prime-generator.knativetutorial.example.com"  http://${IP_ADDRESS}/?sleep=3&upto=10000&memload=100

watch kubectl get pods
NAME                                            READY   STATUS    RESTARTS   AGE
prime-generator-v1-deployment-954dd97b4-cf6sc   2/2     Running   0          44s
prime-generator-v1-deployment-954dd97b4-lhrvn   2/2     Running   0          42s
prime-generator-v1-deployment-954dd97b4-mbk5z   2/2     Running   0          47s
prime-generator-v1-deployment-954dd97b4-n6tr6   2/2     Running   0          42s
prime-generator-v1-deployment-954dd97b4-pjhzt   2/2     Running   0          44s



kubectl apply -n knativetutorial -f service-min-max-scale.yaml


curl -H "Host:prime-generator.knativetutorial.example.com" $IP_ADDRESS/?sleep=3&upto=10000&memload=100



kubectl -n knativetutorial delete services.serving.knative.dev greeter  &&\
kubectl -n knativetutorial delete services.serving.knative.dev prime-generator

Knative Eventing

kubens knativetutorial

kubectl apply -f eventing-hello-sink.yaml

curl -H "Host:eventinghello.knativetutorial.example.com" $IP_ADDRESS

kubectl apply -f eventinghello-source.yaml

Knative kafka

kubens kafka

curl -L https://github.com/strimzi/strimzi-kafka-operator/releases/download/0.16.2/strimzi-cluster-operator-0.16.2.yaml \
  | sed 's/namespace: .*/namespace: kafka/' \
  | kubectl apply -n kafka -f -

cd eventing

kubectl -n kafka apply -f kafka-broker-my-cluster.yaml

watch kubectl get pods

kubectl get kafkas

kubectl -n kafka create -f kafka-topic-my-topic.yaml

kubectl -n kafka  get kafkatopics

kubectl exec -it -c kafka my-cluster-kafka-0 -- bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic my-topic

Topic: my-topic	PartitionCount: 10	ReplicationFactor: 1	Configs:

export TUTORIAL_HOME=/Users/burrsutter/11steps/knative-tutorial

$TUTORIAL_HOME/bin/kafka-producer.sh

$TUTORIAL_HOME/bin/kafka-consumer.sh

kubectl apply \
-f https://github.com/knative/eventing-contrib/\
releases/download/v0.12.2/kafka-source.yaml

watch kubectl get pods -n knative-sources

watch kubectl get pods -n knative-eventing


curl -L "https://github.com/knative/eventing-contrib/\
releases/download/v0.12.2/kafka-channel.yaml" \
 | sed 's/REPLACE_WITH_CLUSTER_URL/my-cluster-kafka-bootstrap.kafka:9092/' \
 | kubectl apply --filename -

kubectl api-resources --api-group='sources.eventing.knative.dev'

kubectl api-resources --api-group='messaging.knative.dev'

kubectl apply -f eventing-hello-sink.yaml

stern eventinghello

curl -H "Host:eventinghello.kafka.example.com" $IP_ADDRESS

allow it to scale to zero

kubectl apply -f eventinghello-source.yaml

see if cron starts it up

kubectl delete -f eventinghello-source.yaml

kubectl apply -f mykafka-source.yaml

$TUTORIAL_HOME/bin/kafka-producer.sh

{"hey": "duniya"}
{"bonjour":"le monde"}
{"hola":"mundo"}

kubectl -n kafka run kafka-spammer --image=quay.io/burrsutter/kafkaspammer:1.0.2
KAFKA_SPAMMER_POD=$(kubectl -n kafka get pod -l "run=kafka-spammer" \
 -o jsonpath='{.items[0].metadata.name}')

kubectl -n kafka exec -it $KAFKA_SPAMMER_POD -- /bin/sh

curl localhost:8080/3

Tekton Pipelines

scripts-knative's People

Contributors

burrsutter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.