Skip to content

Instantly share code, notes, and snippets.

@smijar
Last active June 3, 2022 16:10
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 smijar/d7361900302b9fe7853d315caf17bca8 to your computer and use it in GitHub Desktop.
Save smijar/d7361900302b9fe7853d315caf17bca8 to your computer and use it in GitHub Desktop.

install knative plugins locally

# ref: https://knative.dev/docs/getting-started/quickstart-install/#install-the-knative-cli
echo
echo "installing knative with kind cluster..."
echo "downloading kn CLI"
sudo curl -s -Lo /usr/local/bin/kn https://github.com/knative/client/releases/download/knative-v1.4.1/kn-linux-amd64
sudo chmod +x /usr/local/bin/kn
sleep 2
echo
echo "downloading kn quickstart plugin binary"
sudo curl -s -Lo /usr/local/bin/kn-quickstart https://github.com/knative-sandbox/kn-plugin-quickstart/releases/download/knative-v1.4.0/kn-quickstart-linux-amd64
sudo chmod +x /usr/local/bin/kn-quickstart
echo
echo "checking knative quickstart plugin"
kn quickstart --help
echo

start kind cluster

echo
echo starting knative kind cluster...
kn quickstart kind
sleep 15
echo "getting clusters to verify"
kind get clusters
echo

patch kind cluster to install kontain

echo
echo patch knative serving to use Kourier by default
kubectl patch configmap/config-network \
	--namespace knative-serving \
	--type merge \
	--patch '{"data":{"ingress-class":"kourier.ingress.networking.knative.dev"}}'

echo "patching configmap/config-features to enable podspec.runtimeclassname for installing KM..."
kubectl patch configmap/config-features \
	-n knative-serving \
	--type merge \
	-p '{"data":{"kubernetes.podspec-runtimeclassname": "enabled"}}'

sleep 5
echo "applying Kontain daemonset yaml..."
kubectl apply -f https://raw.githubusercontent.com/kontainapp/guide-examples/master/infra/kustomize_outputs/km.yaml

sleep 5

echo "waiting for kontain-node-initializer to be ready..."
kubectl -n kube-system wait pod --for=condition=Ready -l name=kontain-node-initializer --timeout=240s

sleep 5
echo "saving log output of kontain-node-initiliazer daemonset pod"
kubectl logs daemonset/kontain-node-initializer -n kube-system > /tmp/kontain-node-initializer-kind.log

sleep 20
kubectl get po -A
cat /tmp/kontain-node-initializer-kind.log

test a service

echo creating service...
# kn service create hello-kontain --image gcr.io/knative-samples/helloworld-go --port 8080 --env TARGET=World
kubectl apply -f k8s.yml

where k8s.yml is shown below:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-kontain
spec:
  template:
    spec:
      runtimeClassName: kontain
      containers:
        - image: kontainguide/golang-http-hello:1.0 # gcr.io/knative-samples/helloworld-go
          ports:
            - containerPort: 8080
          env:
            - name: TARGET
              value: "World"

list services

echo getting service list...
kn service list

address of service

echo getting address of service...
curl $(kn service describe hello-kontain -o url)

invoke service

echo invoking service...
curl $(kn service describe hello -o url)
@johnmuth81
Copy link

The instructions here didn't quite work for me.

  1. The kubectl patch command didn't get runtimes enabled in config-features correctly.
  2. The kn service create command doesn't allow runtime to be set. You need to use 1kubectl apply -f`.
    The instructions for gVisor (https://gvisor.dev/docs/tutorials/knative/) are what I used to get things working.

@smijar
Copy link
Author

smijar commented Jun 3, 2022

Thanks for checking on this. Awesome review. I used the gvisor page as well.

I came up with the patch command to automate the kubectl edit command that was in gvisor. It has worked in the past for me on both EKS and Kops and kind, but will check it again definitely to make sure.

Yup, I need to alter the doc for kn service create for our service type, agreed. I have it that way in Makefile, but think I forgot to document in this doc.

the readme in guide-examples does use kubectl:
https://github.com/kontainapp/guide-examples/tree/master/examples/knative/basics

@smijar
Copy link
Author

smijar commented Jun 3, 2022

Updated with the k8s.yml file for the service, and the patch equivalent for kourier and kontain after just trying on a kops cluster. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment