Skip to content

Instantly share code, notes, and snippets.

@halvards
Last active September 14, 2021 09:47
Show Gist options
  • Save halvards/6db74362fe568ec068caa28ce2787051 to your computer and use it in GitHub Desktop.
Save halvards/6db74362fe568ec068caa28ce2787051 to your computer and use it in GitHub Desktop.
Knative using Minikube on macOS

Install Knative using Minikube on macOS

This will install Istio 0.8.0 and Knative 0.1.0 on a Minikube cluster running Kubernetes 1.10.6, and then deploy a sample application.

Install prerequisites

Install kubectl (https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-with-homebrew-on-macos):

brew install kubernetes-cli

Install watch (https://gitlab.com/procps-ng/procps):

brew install watch

Install Minikube (https://github.com/kubernetes/minikube/blob/master/README.md#minikube):

brew cask install minikube

Install HyperKit (https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver):

curl -Lo docker-machine-driver-hyperkit https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit \
&& chmod +x docker-machine-driver-hyperkit \
&& sudo cp docker-machine-driver-hyperkit /usr/local/bin/ \
&& rm docker-machine-driver-hyperkit \
&& sudo chown root:wheel /usr/local/bin/docker-machine-driver-hyperkit \
&& sudo chmod u+s /usr/local/bin/docker-machine-driver-hyperkit

Create the Kubernetes cluster

Create and start the K8s cluster (https://github.com/knative/docs/blob/master/install/Knative-with-Minikube.md#creating-a-kubernetes-cluster):

minikube start --profile=knative --memory=8192 --cpus=4 \
  --kubernetes-version=v1.10.6 --vm-driver=hyperkit --bootstrapper=kubeadm \
  --extra-config=controller-manager.cluster-signing-cert-file="/var/lib/localkube/certs/ca.crt" \
  --extra-config=controller-manager.cluster-signing-key-file="/var/lib/localkube/certs/ca.key" \
  --extra-config=apiserver.admission-control="LimitRanger,NamespaceExists,NamespaceLifecycle,ResourceQuota,ServiceAccount,DefaultStorageClass,MutatingAdmissionWebhook"

Install Istio (https://github.com/knative/docs/blob/master/install/Knative-with-Minikube.md#installing-istio):

curl -L https://raw.githubusercontent.com/knative/serving/v0.1.0/third_party/istio-0.8.0/istio.yaml \
  | sed 's/LoadBalancer/NodePort/' \
  | kubectl apply -f - \
&& kubectl label namespace default istio-injection=enabled

Wait for all Istio pods to show a STATUS of Running or Completed:

watch kubectl -n istio-system get pods

Install Knative (https://github.com/knative/docs/blob/master/install/Knative-with-Minikube.md#installing-knative-serving):

curl -L https://github.com/knative/serving/releases/download/v0.1.0/release-lite.yaml \
  | sed 's/LoadBalancer/NodePort/' \
  | kubectl apply -f -

Wait for all Knative serving pods to show a STATUS of Running:

watch kubectl -n knative-serving get pods

Deploy a sample application

Create the helloworld-go Knative service (service.serving.knative.dev) manifest (https://github.com/knative/docs/blob/master/install/getting-started-knative-app.md#configuring-your-deployment):

cat << EOF > helloworld-go-service.yaml
apiVersion: serving.knative.dev/v1alpha1 # Current version of Knative
kind: Service
metadata:
  name: helloworld-go # The name of the app
  namespace: default # The namespace the app will use
spec:
  runLatest:
    configuration:
      revisionTemplate:
        spec:
          container:
            image: gcr.io/knative-samples/helloworld-go # The URL to the image of the app
            env:
            - name: TARGET # The environment variable printed out by the sample app
              value: "Go Sample v1"
EOF

Deploy the helloworld-go service.serving.knative.dev manifest:

kubectl apply -f helloworld-go-service.yaml

Check that there is a Knative service for helloworld-go:

kubectl get service.serving.knative.dev

View the details of the helloworld-go Knative service:

kubectl get service.serving -o yaml

Get the assigned hostname for the helloworld-go service:

export APP_HOST=$(kubectl get services.serving helloworld-go -o jsonpath='{.status.domain}') && echo $APP_HOST

Get the IP address for your Minikube cluster:

export MINIKUBE_IP=$(minikube ip --profile=knative) && echo $MINIKUBE_IP

Get the node port for the helloworld-go service:

export APP_PORT=$(kubectl -n istio-system get svc knative-ingressgateway -o 'jsonpath={.spec.ports[?(@.port==80)].nodePort}') && echo $APP_PORT

Change the scale-to-zero-threshold property of the Knative autoscaler from 5m to 30s:

kubectl -n knative-serving edit configmap config-autoscaler

In a side-by-side terminal window, watch for a helloworld-go pod (with three containers) in the default namespace of your cluster as you complete the following steps:

watch -n 0.5 kubectl get pods

Send a HTTP GET request to the helloworld-go service:

curl -sH "Host: ${APP_HOST}" http://${MINIKUBE_IP}:${APP_PORT}

Look at the details of the pod:

kubectl describe pods

Look at the deployments in the knative-serving namespace:

kubectl -n knative-serving get deployments

Clean up

Delete the helloworld-go service from the cluster:

kubectl delete -f helloworld-go-service.yaml

Stop the K8s cluster:

minikube stop --profile=knative

Delete the K8s cluster:

minikube delete --profile=knative
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment