Example Ruby application to deploy to Knative, which shows environment variables
Go to file
starkandwayne-bot 86f623bf50 Updating CODE_OF_CONDUCT.md 2019-01-15 15:48:00 -05:00
docs/images example of myvars 2018-11-27 11:38:26 +10:00
CODE_OF_CONDUCT.md Updating CODE_OF_CONDUCT.md 2019-01-15 15:48:00 -05:00
Gemfile initial port of cf-env 2018-11-27 11:35:55 +10:00
Gemfile.lock initial port of cf-env 2018-11-27 11:35:55 +10:00
Procfile initial port of cf-env 2018-11-27 11:35:55 +10:00
README.md header 2018-11-27 11:51:31 +10:00
config.ru initial port of cf-env 2018-11-27 11:35:55 +10:00
env.rb initial port of cf-env 2018-11-27 11:35:55 +10:00

README.md

Display Knative environment variables

A simple Sinatra application. Once deployed to Knative, it will echo the Environment and HTTP Request Headers.

demo

Install Knative

To install the knctl CLI on MacOS:

brew install starkandwayne/kubernetes/knctl

To install Knative, and its Istio dependency, into your current Kubernetes:

knctl install --exclude-monitoring

Later, you can uninstall Knative/Istio:

knctl uninstall

Deploy from Docker image

The repo contains a manifest file which creates a new application called cfenv, with a random string in the URL to avoid collisions.

To deploy from existing Docker image:

knctl deploy -s knative-env -i index.docker.io/drnic/knative-env

Deploy with additional environment variables:

knctl deploy -s knative-env -i index.docker.io/drnic/knative-env \
    --env MYVAR1=test1 \
    --env MYVAR2=test2

myvars

Deploy from source with Ruby buildpack

To deploy from source, whilst creating new intermediate Docker image (in Docker Hub in example below):

knctl basic-auth-secret create -s registry --docker-hub -u <you> -p <password>
knctl service-account create --service-account build -s registry

kubectl apply -f https://raw.githubusercontent.com/knative/build-templates/master/buildpack/buildpack.yaml

DOCKER_IMAGE=index.docker.io/<you>/knative-env
knctl deploy -s knative-env -i ${DOCKER_IMAGE} \
    --service-account build \
    --template buildpack \
    --directory .

Local Network Access

To view in browser, either setup Ingress and DNS, or use kwt as below. All routes from Knative will now work from local machine:

sudo -E kwt net start --dns-map-exec='knctl dns-map'

By default, your application will be viewable at http://knative-env.default.example.com

Delete

To delete the application and all its Knative artifacts (Kubernetes CRDs):

knctl service delete -s knative-env

More tutorials

Follow our Knative series of articles to learn more about Knative and Kubernetes.

https://starkandwayne.com/blog/introduction-to-knative/