Skip to content

daisy-ycguo/knative-learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Study Knative

This repo contains useful steps to install Knative, test app on Knative and understand Knative.

Install

  1. Install istio
kubectl apply -f istio.yaml
kubectl label namespace default istio-injection=enabled
# Check pods are running
kubectl get pods -n istio-system
  1. Install build and serving
kubectl apply -f https://github.com/knative/serving/releases/download/v0.3.0/serving.yaml
# Check pods are running
kubectl get pods -n knative-serving
kubectl get pods -n knative-build
  1. Install your first app
kubectl apply -f service.yaml
# Check your pod is running
kubectl get Pods

# Get the public IP of knative-ingressgateway
export KINGRESS_IP=`kubectl get svc istio-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*].ip}"`
# Get url
export HELLOWORLD_URL=$(kubectl get services.serving.knative.dev helloworld-go  -o jsonpath='{.status.domain}')
# Test your app
curl -H "Host: helloworld-go.default.svc.cluster.local" http://130.198.86.58

# Delete your deployment
kubectl delete -f service.yaml
  1. A source to url sample
#Install the kaniko build template
kubectl apply -f kaniko.yaml
#Register secrets for Docker Hub
kubectl apply -f docker-secret.yaml
#Build and deploy
kubectl apply -f builder.yaml
# Get ip address of istio-ingressgateway
kubectl get pods -n istio-system -o wide | grep "istio-ingressgateway"
#Get the port
echo $(kubectl get svc knative-ingressgateway -n istio-system   -o 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
# Get the public IP for the private IP if you are using a public cloud
export IP_ADDRESS=<your public ip>:<port>
#Get the app URL
export HOST_URL=$(kubectl get services.serving.knative.dev app-from-source  -o jsonpath='{.status.domain}')
# Test your app
curl -H "Host: ${HOST_URL}" http://${IP_ADDRESS}

# Delete your deployment
kubectl delete -f builder.yaml
kubectl delete -f docker-secret.yaml
kubectl delete -f kaniko.yaml
  1. Eventing trial
#Install
kubectl apply -f https://github.com/knative/eventing/releases/download/v0.3.0/release.yaml
#Install three eventsource type
kubectl apply -f https://github.com/knative/eventing-sources/releases/download/v0.3.0/release.yaml

#Github samples
#Create a github-message-dumper service
kubectl apply -f ./github-event-sample/service.yaml
kubectl apply -f ./github-event-sample/githubsecret.yaml
kubectl apply -f ./github-event-sample/github-source.yaml

Test with

export KINGRESS_IP=`kubectl get svc knative-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*].ip}"`
curl -X POST -H "Host: githubsourcesample-xzgp7.default.example.com" -H "X-GitHub-Event: pull_request" -H "X-Hub-Signature: sha1=7d38cdd689735b008b3c702edd92eea23791c5f6" -H "X-Github-Delivery: 72d3162e-cc78-11e3-81ab-4c9367dc0958" -d @payload.json http://${KINGRESS_IP}
  1. Logging, monitoring and metrics

Set up

Note If you are using IKS, add below mountPath and hostPath to DaemonSet fluentd-ds

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-ds
  namespace: knative-monitoring
spec:
  template:
    spec:
      containers:
        volumeMounts:
        - mountPath: /var/data/cripersistentstorage
          name: persistentstorage
          readOnly: true
      volumes:
      - hostPath:
          path: /var/data/cripersistentstorage
        name: persistentstorage

Then

# Label node to start Fluentd DaemonSet
kubectl label nodes --all beta.kubernetes.io/fluentd-ds-ready="true"
# check
kubectl get daemonset fluentd-ds --namespace knative-monitoring
# start proxy
kubectl proxy
# start a local proxy of Grafana
kubectl port-forward --namespace knative-monitoring $(kubectl get pods --namespace knative-monitoring --selector=app=grafana --output=jsonpath="{.items..metadata.name}") 3000

Sample app: telemetry-go

Use telemetry-go as the sample app.

# Build docker image
cd $GOPATH/src/github.com/knative/docs
docker build \
  --tag "daisyycguo/knative-telemetry" \
  --file=serving/samples/telemetry-go/Dockerfile .
docker push daisyycguo/knative-telemetry

# Apply
kubectl apply -f ./telemetry-go/
export KINGRESS_IP=`kubectl get svc knative-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*].ip}"`
export TELEMETRY_HOST=`kubectl get route telemetrysample-route --output jsonpath="{.status.domain}"`
curl -H "Host:$TELEMETRY_HOST" http://${KINGRESS_IP}
curl -H "Host:$TELEMETRY_HOST" http://${KINGRESS_IP}/log
curl -H "Host:telemetrysample-route.default.example.com" http://168.1.195.91/log

# Exporting
kubectl proxy
kubectl -n knative-monitoring port-forward $(kubectl -n knative-monitoring get pod -l app=prometheus -o jsonpath="{.items[0].metadata.name}") 9090
kubectl port-forward --namespace knative-monitoring $(kubectl get pods --namespace knative-monitoring --selector=app=grafana --output=jsonpath="{.items..metadata.name}") 3000
  • Visit Kibana UI to get logs. Use kubernetes.labels.serving_knative_dev\/revision: : "telemetrysample-configuration-00001" to search logs of this revision. Use kubernetes.labels.serving_knative_dev\/configuration: "telemetrysample-configuration" to search logs of this configuration.
  • Visit Zipkin to get trace.
  • Visit Prometheus UI to get metrics. Use istio_revision_request_duration_sum{destination_configuration="telemetrysample-configuration"} and istio_revision_request_count{destination_configuration="telemetrysample-configuration"} to search metrics.
  • Visit Grafana to get metrics.
# Customize prometheus
kubectl port-forward $(kubectl get pods --selector=app=prometheus-test --output=jsonpath="{.items[0].metadata.name}") 9090
# Access http://localhost:9090

Delete resources

kubectl delete -f ./telemetry-go/

Sample app: blue/green deployment

kubectl apply -f ./blue-green-demo/blue-green-demo-config.yaml
kubectl apply -f ./blue-green-demo/blue-green-demo-route.yaml
export KINGRESS_IP=`kubectl get svc knative-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*].ip}"`
export BLUEGREEN_DEMO_HOST=`kubectl get route blue-green-demo --output jsonpath="{.status.domain}"`
curl -H "Host: $BLUEGREEN_DEMO_HOST" http://$KINGRESS_IP

# Change config from blue to green
# Change route to send traffic to V1 and send 0 traffic to V2 but with name route
kubectl apply -f ./blue-green-demo/blue-green-demo-config.yaml
kubectl apply -f ./blue-green-demo/blue-green-demo-route.yaml
curl -H "Host: $BLUEGREEN_DEMO_HOST" http://$KINGRESS_IP
curl -H "Host: v2.$BLUEGREEN_DEMO_HOST" http://$KINGRESS_IP

# Change route to half and half
kubectl apply -f ./blue-green-demo/blue-green-demo-route.yaml
curl -H "Host: $BLUEGREEN_DEMO_HOST" http://$KINGRESS_IP

# delete
kubectl delete route blue-green-demo
kubectl delete configuration blue-green-demo

Appendix

Open prometheus Web UI:

kubectl -n knative-monitoring port-forward $(kubectl -n knative-monitoring get pod -l app=prometheus -o jsonpath="{.items[0].metadata.name}") 9090

kubectl port-forward $(kubectl get pods --selector=app=prometheus-test --output=jsonpath="{.items[0].metadata.name}") 9090

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published