Automating your Services with Knative and Solo.io Gloo

Automating your Services with Knative and Solo.

io GlooScott CrantonBlockedUnblockFollowFollowingMar 19Photo by Louis Reed on UnsplashKnative is being talked about a great deal, especially around how its capabilities can help provide more standard building blocks on top of Kubernetes for building microservices and serverless like services, e.

g.

scale to zero, and scale on demand.

Knative high level has three capability areas: building, serving, and eventing.

This post will provide some examples around Knative Build and Knative Serving with Solo.

io Gloo.

Knative Serving initially included all of Istio to just use its capabilities around Kubernetes cluster ingress.

Recently the Knative team added Gloo as an alternative to Istio.

More details are available in Gloo, Knative and the future of Serverless and Gloo, by Solo.

io, is the first alternative to Istio on Knative.

This post shows a quick example of Knative Building, Knative Serving and Gloo integration.

All of the Kubernetes Manifests are located in the following GitHub repo https://github.

com/scranton/helloworld-knative.

Encourage you to clone and/or fork this repo to help you try these examples yourself.

SetupThese instructions assume you are running on a clean, recent minikube install locally, and that you also have kubectl available locally.

Install GlooOn Mac or Linux, the quickest option is to use Homebrew.

Full install instructions at Gloo documentation.

brew install glooctlThen assuming you’ve got a running minikube, and kubectl setup against that minikube instance, i.

e.

kubectl config current-context returns minikube, run the following to install Gloo with Knative Serving.

glooctl install knativeDeploy pre-existing example imageI’ve already built this example, and have hosted the image publicly in my Docker Hub repo.

To use Knative to serve up this existing image, you just need to do the following command.

kubectl apply –filename service.

yamlVerify domain URL for service.

Should be helloworld-go.

default.

example.

com.

kubectl get ksvc helloworld-go -n default –output=custom-columns=NAME:.

metadata.

name,DOMAIN:.

status.

domainAnd test the service.

CLUSTERINGRESS_URL=$(glooctl proxy url –name clusteringress-proxy)curl -H "Host: helloworld-go.

default.

example.

com" ${CLUSTERINGRESS_URL}To clean up, delete the resources.

kubectl delete –filename service.

yamlBuild locally, and deploy using Knative ServingRun docker build with your Docker Hub username.

docker build -t {docker username}/helloworld-go .

docker push {docker username}/helloworld-goDeploy the service.

Again, make sure you updated username in service.

yaml file, i.

e.

replace image referencedocker.

io/scottcranton/helloworld-go with your Docker Hub username.

kubectl apply –filename service.

yamlVerify domain URL for service.

Should be helloworld-go.

default.

example.

com.

kubectl get ksvc helloworld-go -n default –output=custom-columns=NAME:.

metadata.

name,DOMAIN:.

status.

domainAnd test your service.

CLUSTERINGRESS_URL=$(glooctl proxy url –name clusteringress-proxy)curl -H "Host: helloworld-go.

default.

example.

com" ${CLUSTERINGRESS_URL}To clean up, delete the resources.

kubectl delete –filename service.

yamlBuild using Knative Build, and deploy using Knative ServingTo install Knative Build, do the following.

I’m using the kaniko build template, so you'll also need to install that as well.

kubectl apply –filename https://github.

com/knative/build/releases/download/v0.

4.

0/build.

yamlkubectl apply –filename https://raw.

githubusercontent.

com/knative/build-templates/master/kaniko/kaniko.

yamlTo verify the Knative Build install, do the following.

kubectl get pods –namespace knative-buildI’d encourage forking my example repo (https://github.

com/scranton/helloworld-knative), so you can push code changes and see them in your environment.

Update secret.

yaml with base64 encoded versions of your Docker Hub credentials.

piVersion: v1kind: Secretmetadata: name: basic-user-pass annotations: build.

knative.

dev/docker-0: https://index.

docker.

io/v1/type: kubernetes.

io/basic-authstringData: username: { Docker Hub username | base64 } password: { Docker Hub password | base64 }Update service.

yaml with your Docker Hub information.

apiVersion: serving.

knative.

dev/v1alpha1kind: Servicemetadata: name: helloworld-go namespace: defaultspec: runLatest: configuration: revisionTemplate: spec: container: image: docker.

io/{ Docker Hub username }/helloworld-go imagePullPolicy: Always env: – name: TARGET value: "Go Sample v1"Update service-build.

yaml with your GitHub and Docker usernames.

This manifest will use Knative Build to create an image using the kaniko-build build template, and deploy the service using Knative Serving with Gloo.

apiVersion: serving.

knative.

dev/v1alpha1kind: Servicemetadata: name: helloworld-go namespace: defaultspec: runLatest: configuration: build: apiVersion: build.

knative.

dev/v1alpha1 kind: Build metadata: name: kaniko-build spec: serviceAccountName: build-bot source: git: url: https://github.

com/{ GitHub username }/helloworld-knative revision: master template: name: kaniko arguments: – name: IMAGE value: docker.

io/{ Docker Hub username }/helloworld-go timeout: 10m revisionTemplate: spec: container: image: docker.

io/{ Docker Hub username }/helloworld-go imagePullPolicy: Always env: – name: TARGET value: "Go Sample v1"To Deploy, apply the following manifests.

kubectl apply –filename servet.

yaml –filename serviceaccount.

yaml –filename service-build.

yamlThen you can watch the build and deployment happening.

kubectl get pods –watchOnce you see all the helloworld-go-0000x-deployment-.

pods are ready, then you can Ctrl+C to escape the watch, and then test your deployment.

Verify domain URL for service.

Should be helloworld-go.

default.

example.

com.

kubectl get ksvc helloworld-go -n default –output=custom-columns=NAME:.

metadata.

name,DOMAIN:.

status.

domainAnd test your service.

CLUSTERINGRESS_URL=$(glooctl proxy url –name clusteringress-proxy)curl -H "Host: helloworld-go.

default.

example.

com" ${CLUSTERINGRESS_URL}Cleanupkubectl delete –filename secret.

yaml –filename serviceaccount.

yaml –filename service-build.

yamlSummaryHopefully, this post gave you a taste for how Gloo and Knative can work together to provide you with a way to build and deploy your services on demand into Kubernetes.

See Alsohttps://github.

com/knative/docs/blob/master/install/getting-started-knative-app.

mdhttps://github.

com/knative/docshttps://gloo.

solo.

io/getting_started/kubernetes/gloo_with_knative/.. More details

Leave a Reply