1. Project Overview & Quickstart (alexellis/build)
build
The official build framework for the Armbian Linux distribution. This repository contains the complete toolchain and scripts required to compile custom OS images from source, including kernel configuration, U-Boot handling, and board-specific tweaks for various ARM and ARM64 single-board computers.
Repository Details
- Repository: alexellis/build
- GitHub Stars: โญ 5,342
- Primary Language: Shell
Note: High-volume repository documentation is actively indexed and synchronized by YakaAI.
2. Official Technical Reference & Guides (alexellis/docs)
File: README.md
Welcome to the source file repository for Knative documentation
View published docs
Use the Knative Documentation website to view the
docs and learn about Knative.
Source files
View the source files if you want to contribute a fix or add new content. Each
release of the Knative docs are
branched. If you are looking for an
archived doc set, see the list of available versions in
Knative doc releases.
File: community/samples/serving/helloworld-vertx/README.md
Hello World - Eclipse Vert.x sample
Learn how to deploy a simple web app that is written in Java and uses Eclipse
Vert.x. This samples uses Docker to build locally. The app reads in a TARGET
env variable and then prints "Hello World: ${TARGET}!". If a value for TARGET
is not specified, the "NOT SPECIFIED" default value is used.
Use this sample to walk you through the steps of creating and modifying the
sample app, building and pushing your container image to a registry, and then
deploying your app to your Knative cluster.
Before you begin
You must meet the following requirements to complete this sample:
- A version of the Knative Serving component installed and running on your
Kubernetes cluster. Follow the
Knative installation instructions if you need to
create a Knative cluster. - The following software downloaded and install on your loacal machine:
- Java SE 8 or later JDK.
- Eclipse Vert.x v3.5.4.
- Docker for building and pushing your container
image. - curl to test the sample app after deployment.
- A Docker Hub account where you can push your
container image.
Tip: You can clone the Knatve/docs repo
and then modify the source files. Alternatively, learn more by manually creating
the files youself.
Creating and configuring the sample code
To create and configure the source files in the root of your working directory:
Create the
pom.xmlfile:text
/* Detailed source-code truncated for AI context efficiency. */
1. Create the `HelloWorld.java` file in the
`src/main/java/com/example/helloworld` directory. The
`[ROOT]/src/main/java/com/example/helloworld/HelloWorld.java` file creates a
basic web server that listens on port `8080`.
```java
package com.example.helloworld;
import io.reactivex.Flowable;
import io.vertx.reactivex.core.AbstractVerticle;
import io.vertx.reactivex.core.http.HttpServer;
import io.vertx.reactivex.core.http.HttpServerRequest;
public class HelloWorld extends AbstractVerticle {
public void start() {
final HttpServer server = vertx.createHttpServer();
final Flowable<HttpServerRequest> requestFlowable = server.requestStream().toFlowable();
requestFlowable.subscribe(httpServerRequest -> {
String target = System.getenv("TARGET");
if (target == null) {
target = "NOT SPECIFIED";
}
httpServerRequest.response().setChunked(true)
.putHeader("content-type", "text/plain")
.setStatusCode(200) // OK
.end("Hello World: " + target);
});
server.listen(8080);
}
}Create the
Dockerfilefile:docker# Use fabric8's s2i Builder image. # https://hub.docker.com/r/fabric8/s2i-java FROM fabric8/s2i-java:2.0 # Service must listen to $PORT environment variable. # This default value facilitates local development. ENV PORT 8080 # Copy the JAR file to the deployment directory. ENV JAVA_APP_DIR=/deployments COPY target/helloworld-1.0.0-SNAPSHOT.jar /deployments/Create the
service.yamlfile. You must specify your Docker Hub username in{username}. You can also configure theTARGET, for example you can modify
theEclipse Vert.x Sample v1value.yamlapiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: helloworld-vertx namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: docker.io/{username}/helloworld-vertx env: - name: TARGET value: "Eclipse Vert.x Sample v1"
Building and deploying the sample
To build a container image, push your image to the registry, and then deploy
your sample app to your cluster:
Use Docker to build your container image and then push that image to your
Docker Hub registry. You must replace the{username}variables in the
following commands with your Docker Hub username.shell# Build the container on your local machine docker build -t {username}/helloworld-vertx . # Push the container to docker registry docker push {username}/helloworld-vertxNow that your container image is in the registry, you can deploy it to your
Knative cluster by running thekubectl applycommand:shellkubectl apply --filename service.yamlResult: A service name
helloworld-vertxis created in your cluster along
with the following resources:- A new immutable revision for the version of the app that you just deployed.
- The following networking resources are created for your app:
- route
- ingress
- service
- load balancer
- Auto scaling is enable to allow your pods to scale up to meet traffic, and
also back down to zero when there is no traffic.
Testing the sample app
To verify that your sample app has been successfully deployed:
View your the ingress IP address of your service by running the following
kubectl getcommand. Note that it may take sometime for the new service to
get asssigned an external IP address, especially if your cluster was newly
created.shell# In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`. INGRESSGATEWAY=knative-ingressgateway # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x. # Use `istio-ingressgateway` instead, since `knative-ingressgateway` # will be removed in Knative v0.4. if kubectl get configmap config-istio -n knative-serving &> /dev/null; then INGRESSGATEWAY=istio-ingressgateway fi kubectl get svc $INGRESSGATEWAY --namespace istio-systemExample result:
shellNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE xxxxxxx-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2dRetrieve the URL for your service, by running the following
kubectl get
command:shellkubectl get services.serving.knative.dev helloworld-vertx --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domainExample result:
shellNAME DOMAIN helloworld-vertx helloworld-vertx.default.example.comRun the following
curlcommand to test your deployed sample app. You must
replace the{IP_ADDRESS}variable the URL that your retrieve in the
previous step.shellcurl -H "Host: helloworld-vertx.default.example.com" http://{IP_ADDRESS}Example result:
shellHello World: Eclipse Vert.x Sample v1
Congtratualations on deploying your sample Java app to Knative!
Removing the sample app deployment
To remove the sample app from your cluster, run the following kubectl delete
command:
kubectl delete --filename service.yamlFile: community/samples/serving/helloworld-swift/README.md
Hello World - Swift sample
A simple web app written in Swift that you can use for testing. The app reads in
an env variable TARGET and prints "Hello ${TARGET}!". If TARGET is not
specified, the app uses "World" as the TARGET.
Prerequisites
- You must have a Kubernetes cluster with Knative installed. If you need to
create a cluster, follow the
installation instructions. - You must have Docker installed and running on your
local machine, and a Docker Hub account configured (used for container
registry).
Recreating the sample code
While you can clone all of the code from this directory, it might be more useful
if you build this app step-by-step. The following instructions recreate the
source files from this folder.
Create a the
Package.swiftto declare your package and its dependencies.
This app uses Swifter, a tiny http
server engine for Swift.swift// swift-tools-version:4.0 import PackageDescription let package = Package( name: "HelloSwift", dependencies: [ .package(url: "https://github.com/httpswift/swifter.git", .upToNextMajor(from: "1.4.5")) ], targets: [ .target( name: "HelloSwift", dependencies: ["Swifter"], path: "./Sources") ] )Add the web server code to a file named
main.swiftin aSources/HelloSwift/folder:swiftimport Swifter import Dispatch import Foundation let server = HttpServer() server["/"] = { r in let target = ProcessInfo.processInfo.environment["TARGET"] ?? "World" return HttpResponse.ok(.html("Hello \(target)")) } let semaphore = DispatchSemaphore(value: 0) do { let port = UInt16(ProcessInfo.processInfo.environment["PORT"] ?? "8080") try server.start(port!, forceIPv4: true) print("Server has started ( port = \(try server.port()) ). Try to connect now...") semaphore.wait() } catch { print("Server start error: \(error)") semaphore.signal() }In your project directory, create a file named
Dockerfileand copy the code
block below into it.dockerfile# Use the official Swift image. # https://hub.docker.com/_/swift FROM swift:4.2 # Copy local code to the container image. WORKDIR /app COPY . . # Install dependencies and build. RUN swift build -c release # Run the web service on container startup. CMD [ ".build/release/HelloSwift"]Create a new file,
service.yaml, and copy the following service definition
into the file. Replace{username}with your Docker Hub username.yamlapiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: helloworld-swift namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: docker.io/{username}/helloworld-swift env: - name: TARGET value: "Swift"
Building and deploying the sample
Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.
Use Docker to build the sample code into a container. To build and push with
Docker Hub, run these commands, replacing{username}with your Docker Hub
username:shell# Build the container on your local machine docker build -t {username}/helloworld-swift . # Push the container to docker registry docker push {username}/helloworld-swiftAfter the build has completed and the container is pushed to Docker Hub, you
can deploy the app into your cluster. Ensure that the container image value
in theservice.yamlfile matches the container you built in the previous
step. Apply the configuration using thekubectlcommand:shellkubectl apply --filename service.yamlNow that your service is created, Knative performs the following steps:
- Creates a new immutable revision for this version of the app.
- Network programming to create a route, ingress, service, and load balancing
for your app. - Automatically scales your pods up and down (including to zero active pods).
To find the IP address for your service, use
kubectl get svc knative-ingressgateway --namespace istio-systemto get the
ingress IP for your cluster. If your cluster is new, it might take sometime
for the service to get asssigned an external IP address.shellkubectl get svc knative-ingressgateway --namespace istio-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE knative-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2dTo find the URL for your service, use the following command:
textkubectl get ksvc helloworld-swift --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain NAME DOMAIN helloworld-swift helloworld-swift.default.example.comNow you can make a request to your app to see the result. Replace
{IP_ADDRESS}with the address you see returned in the previous step:shellcurl -H "Host: helloworld-swift.default.example.com" http://{IP_ADDRESS} Hello Swift
Removing the sample app deployment
To remove the sample app from your cluster, delete the service record:
kubectl delete --filename service.yamlFile: community/samples/serving/helloworld-rust/README.md
Hello World - Rust sample
A simple web app written in Rust that you can use for testing. It reads in an
env variable TARGET and prints "Hello ${TARGET}!". If
TARGET is not specified, it will use "World" as the TARGET.
Prerequisites
- A Kubernetes cluster with Knative installed. Follow the
installation instructions if you need to create
one. - Docker installed and running on your local machine,
and a Docker Hub account configured (we'll use it for a container registry).
Steps to recreate the sample code
While you can clone all of the code from this directory, hello world apps are
generally more useful if you build them step-by-step. The following instructions
recreate the source files from this folder.
Create a new file named
Cargo.tomland paste the following code:toml[package] name = "hellorust" version = "0.0.0" publish = false [dependencies] hyper = "0.12.3" pretty_env_logger = "0.2.3"Create a
srcfolder, then create a new file namedmain.rsin that folder
and paste the following code. This code creates a basic web server which
listens on port 8080:rust#![deny(warnings)] extern crate hyper; extern crate pretty_env_logger; use hyper::{Body, Response, Server}; use hyper::service::service_fn_ok; use hyper::rt::{self, Future}; use std::env; fn main() { pretty_env_logger::init(); let mut port: u16 = 8080; match env::var("PORT") { Ok(p) => { match p.parse::() { Ok(n) => {port = n;}, Err(_e) => {}, }; } Err(_e) => {}, }; let addr = ([0, 0, 0, 0], port).into(); let new_service = || { service_fn_ok(|_| { let mut hello = "Hello ".to_string(); match env::var("TARGET") { Ok(target) => {hello.push_str(&target);}, Err(_e) => {hello.push_str("World")}, }; Response::new(Body::from(hello)) }) }; let server = Server::bind(&addr) .serve(new_service) .map_err(|e| eprintln!("server error: {}", e)); println!("Listening on http://{}", addr); rt::run(server); }In your project directory, create a file named
Dockerfileand copy the code
block below into it.docker# Use the official Rust image. # https://hub.docker.com/_/rust FROM rust:1.27.0 # Copy local code to the container image. WORKDIR /usr/src/app COPY . . # Install production dependencies and build a release artifact. RUN cargo install # Service must listen to $PORT environment variable. # This default value facilitates local development. ENV PORT 8080 # Run the web service on container startup. CMD ["hellorust"]Create a new file,
service.yamland copy the following service definition
into the file. Make sure to replace{username}with your Docker Hub
username.yamlapiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: helloworld-rust namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: docker.io/{username}/helloworld-rust env: - name: TARGET value: "Rust Sample v1"
Build and deploy this sample
Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.
Use Docker to build the sample code into a container. To build and push with
Docker Hub, enter these commands replacing{username}with your Docker Hub
username:shell# Build the container on your local machine docker build -t {username}/helloworld-rust . # Push the container to docker registry docker push {username}/helloworld-rustAfter the build has completed and the container is pushed to Docker Hub, you
can deploy the app into your cluster. Ensure that the container image value
inservice.yamlmatches the container you built in the previous step. Apply
the configuration usingkubectl:shellkubectl apply --filename service.yamlNow that your service is created, Knative will perform the following steps:
- Create a new immutable revision for this version of the app.
- Network programming to create a route, ingress, service, and load balance
for your app. - Automatically scale your pods up and down (including to zero active pods).
To find the IP address for your service, enter these commands to get the
ingress IP for your cluster. If your cluster is new, it may take sometime for
the service to get asssigned an external IP address.shell# In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`. INGRESSGATEWAY=knative-ingressgateway # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x. # Use `istio-ingressgateway` instead, since `knative-ingressgateway` # will be removed in Knative v0.4. if kubectl get configmap config-istio -n knative-serving &> /dev/null; then INGRESSGATEWAY=istio-ingressgateway fi kubectl get svc $INGRESSGATEWAY --namespace istio-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE xxxxxxx-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2dTo find the URL for your service, enter:
textkubectl get ksvc helloworld-rust --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain NAME DOMAIN helloworld-rust helloworld-rust.default.example.comNow you can make a request to your app and see the result. Replace
{IP_ADDRESS}with the address you see returned in the previous step.shellcurl -H "Host: helloworld-rust.default.example.com" http://{IP_ADDRESS} Hello World!
Removing the sample app deployment
To remove the sample app from your cluster, delete the service record:
kubectl delete --filename service.yamlFile: community/samples/serving/helloworld-haskell/README.md
Hello World - Haskell sample
A simple web app written in Haskell that you can use for testing. It reads in an
env variable TARGET and prints "Hello ${TARGET}!". If TARGET is not
specified, it will use "World" as the TARGET.
Prerequisites
- A Kubernetes cluster with Knative installed. Follow the
installation instructions if you need to create
one. - Docker installed and running on your local machine,
and a Docker Hub account configured (we'll use it for a container registry).
Recreating the sample code
While you can clone all of the code from this directory, hello world apps are
generally more useful if you build them step-by-step. The following instructions
recreate the source files from this folder.
Create a new file named
stack.yamland paste the following code:yamlflags: {} packages: - . extra-deps: [] resolver: lts-10.7Create a new file named
package.yamland paste the following codeyamlname: helloworld-haskell version: 0.1.0.0 dependencies: - base >= 4.7 && < 5 - scotty - text executables: helloworld-haskell-exe: main: Main.hs source-dirs: app ghc-options: - -threaded - -rtsopts - -with-rtsopts=-NCreate a
appfolder, then create a new file namedMain.hsin that folder
and paste the following code. This code creates a basic web server which
listens on port 8080:haskell{-# LANGUAGE OverloadedStrings #-} import Data.Maybe import Data.Monoid ((<>)) import Data.Text.Lazy (Text) import Data.Text.Lazy import System.Environment (lookupEnv) import Web.Scotty (ActionM, ScottyM, scotty) import Web.Scotty.Trans main :: IO () main = do t <- fromMaybe "World" <$> lookupEnv "TARGET" pStr <- fromMaybe "8080" <$> lookupEnv "PORT" let p = read pStr :: Int scotty p (route t) route :: String -> ScottyM() route t = get "/" $ hello t hello :: String -> ActionM() hello t = text $ pack ("Hello " ++ t)In your project directory, create a file named
Dockerfileand copy the code
block below into it.docker# Use the official Haskell image to create a build artifact. # https://hub.docker.com/_/haskell/ FROM haskell:8.2.2 as builder # Copy local code to the container image. WORKDIR /app COPY . . # Build and test our code, then build the โhelloworld-haskell-exeโ executable. RUN stack setup RUN stack build --copy-bins # Use a Docker multi-stage build to create a lean production image. # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds FROM fpco/haskell-scratch:integer-gmp # Copy the "helloworld-haskell-exe" executable from the builder stage to the production image. WORKDIR /root/ COPY --from=builder /root/.local/bin/helloworld-haskell-exe . # Service must listen to $PORT environment variable. # This default value facilitates local development. ENV PORT 8080 # Run the web service on container startup. CMD ["./helloworld-haskell-exe"]Create a new file,
service.yamland copy the following service definition
into the file. Make sure to replace{username}with your Docker Hub
username.yamlapiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: helloworld-haskell namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: docker.io/{username}/helloworld-haskell env: - name: TARGET value: "Haskell Sample v1"
Build and deploy this sample
Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.
Use Docker to build the sample code into a container. To build and push with
Docker Hub, enter these commands replacing{username}with your Docker Hub
username:shell# Build the container on your local machine docker build -t {username}/helloworld-haskell . # Push the container to docker registry docker push {username}/helloworld-haskellAfter the build has completed and the container is pushed to Docker Hub, you
can deploy the app into your cluster. Ensure that the container image value
inservice.yamlmatches the container you built in the previous step. Apply
the configuration usingkubectl:shellkubectl apply --filename service.yamlNow that your service is created, Knative will perform the following steps:
- Create a new immutable revision for this version of the app.
- Network programming to create a route, ingress, service, and load balance
for your app. - Automatically scale your pods up and down (including to zero active pods).
To find the IP address for your service, enter these commands to get the
ingress IP for your cluster. If your cluster is new, it may take some time
for the service to get assigned an external IP address.shell# In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`. INGRESSGATEWAY=knative-ingressgateway # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x. # Use `istio-ingressgateway` instead, since `knative-ingressgateway` # will be removed in Knative v0.4. if kubectl get configmap config-istio -n knative-serving &> /dev/null; then INGRESSGATEWAY=istio-ingressgateway fi kubectl get svc $INGRESSGATEWAY --namespace istio-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE xxxxxxx-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2dFor minikube or bare-metal, get IP_ADDRESS by running the following command
shellecho $(kubectl get node --output 'jsonpath={.items[0].status.addresses[0].address}'):$(kubectl get svc $INGRESSGATEWAY --namespace istio-system --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')To find the URL for your service, enter:
textkubectl get ksvc helloworld-haskell --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain NAME DOMAIN helloworld-haskell helloworld-haskell.default.example.comNow you can make a request to your app and see the result. Replace
{IP_ADDRESS}with the address you see returned in the previous step.shellcurl -H "Host: helloworld-haskell.default.example.com" http://{IP_ADDRESS} Hello world: Haskell Sample v1
Removing the sample app deployment
To remove the sample app from your cluster, delete the service record:
kubectl delete --filename service.yamlFile: community/samples/serving/helloworld-dart/README.md
Hello World - Dart sample
A simple web app written in the Dart programming language
that you can use for testing. It reads in the env variable TARGET and prints"Hello $TARGET". If TARGET is not specified, it will use "World" asTARGET.
Prerequisites
- A Kubernetes cluster with Knative installed. Follow the
installation instructions if you need to create
one. - Docker installed and running on your local machine,
and a Docker Hub account configured (we'll use it for a container registry). - dart-sdk installed and
configured if you want to run the program locally.
Recreating the sample code
While you can clone all of the code from this directory, it is useful to know
how to build a hello world Dart application step-by-step. This application can
be created using the following instructions.
Create a new directory and write
pubspec.yamlas follows:yamlname: hello_world_dart publish_to: none # let's not accidentally publish this to pub.dartlang.org Hello world server example in dart. dependencies: shelf: ^0.7.3 environment: sdk: ">=2.0.0 <3.0.0"If you want to run locally, install dependencies. If you only want to run in
Docker or Knative, you can skip this step.shellpub getCreate a new file
bin/main.dartand write the following code:dartimport 'dart:io'; import 'package:shelf/shelf.dart'; import 'package:shelf/shelf_io.dart'; void main() { // Find port to listen on from environment variable. var port = int.tryParse(Platform.environment['PORT']); // Read $TARGET from environment variable. var target = Platform.environment['TARGET'] ?? 'World'; // Create handler. var handler = Pipeline().addMiddleware(logRequests()).addHandler((request) { return Response.ok('Hello $target'); }); // Serve handler on given port. serve(handler, InternetAddress.anyIPv4, port).then((server) { print('Serving at http://${server.address.host}:${server.port}'); }); }Create a new file named
Dockerfile, this file defines instructions for
dockerizing your applications, for dart apps this can be done as follows:dockerfile# Use Google's official Dart image. # https://hub.docker.com/r/google/dart-runtime/ FROM google/dart-runtime # Service must listen to $PORT environment variable. # This default value facilitates local development. ENV PORT 8080Create a new file,
service.yamland copy the following service definition
into the file. Make sure to replace{username}with your Docker Hub
username.yamlapiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: helloworld-dart namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: docker.io/{username}/helloworld-dart env: - name: TARGET value: "Dart Sample v1"
Building and deploying the sample
Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.
Use Docker to build the sample code into a container. To build and push with
Docker Hub, run these commands replacing{username}with your Docker Hub
username:shell# Build the container on your local machine docker build -t {username}/helloworld-dart . # Push the container to docker registry docker push {username}/helloworld-dartAfter the build has completed and the container is pushed to docker hub, you
can deploy the app into your cluster. Ensure that the container image value
inservice.yamlmatches the container you built in the previous step. Apply
the configuration usingkubectl:shellkubectl apply --filename service.yamlNow that your service is created, Knative will perform the following steps:
- Create a new immutable revision for this version of the app.
- Network programming to create a route, ingress, service, and load balance
for your app. - Automatically scale your pods up and down (including to zero active pods).
To find the IP address for your service, use these commands to get the
ingress IP for your cluster. If your cluster is new, it may take sometime for
the service to get asssigned an external IP address.shell# In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`. INGRESSGATEWAY=knative-ingressgateway # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x. # Use `istio-ingressgateway` instead, since `knative-ingressgateway` # will be removed in Knative v0.4. if kubectl get configmap config-istio -n knative-serving &> /dev/null; then INGRESSGATEWAY=istio-ingressgateway fi kubectl get svc $INGRESSGATEWAY --namespace istio-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE xxxxxxx-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2dTo find the URL for your service, use
textkubectl get ksvc helloworld-dart --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain NAME DOMAIN helloworld-dart helloworld-dart.default.example.comNow you can make a request to your app to see the result. Replace
{IP_ADDRESS}with the address you see returned in the previous step.shellcurl -H "Host: helloworld-dart.default.example.com" http://{IP_ADDRESS} Hello Dart Sample v1
Removing the sample app deployment
To remove the sample app from your cluster, delete the service record:
kubectl delete --filename service.yamlFile: community/samples/serving/helloworld-clojure/README.md
Hello World - Clojure sample
A simple web app written in Clojure that you can use for testing. It reads in an
env variable TARGET and prints "Hello ${TARGET}!". If TARGET is not
specified, it will use "World" as the TARGET.
Prerequisites
- A Kubernetes cluster with Knative installed. Follow the
installation instructions if you need to create
one. - Docker installed and running on your local machine,
and a Docker Hub account configured (we'll use it for a container registry).
Recreating the sample code
While you can clone all of the code from this directory, hello world apps are
generally more useful if you build them step-by-step. The following instructions
recreate the source files from this folder.
Create a new file named
src/helloworld/core.cljand paste the following
code. This code creates a basic web server which listens on port 8080:clojure(ns helloworld.core (:use ring.adapter.jetty) (:gen-class)) (defn handler [request] {:status 200 :headers {"Content-Type" "text/html"} :body (str "Hello " (if-let [target (System/getenv "TARGET")] target "World") "!\n")}) (defn -main [& args] (run-jetty handler {:port (if-let [port (System/getenv "PORT")] (Integer/parseInt port) 8080)}))In your project directory, create a file named
project.cljand copy the
code below into it. This code defines the project's dependencies and
entrypoint.clojure(defproject helloworld "1.0.0-SNAPSHOT" :description "Hello World - Clojure sample" :dependencies [[org.clojure/clojure "1.9.0"] [ring/ring-core "1.6.3"] [ring/ring-jetty-adapter "1.6.3"]] :main helloworld.core)In your project directory, create a file named
Dockerfileand copy the code
block below into it. For detailed instructions on dockerizing a Clojure app,
see
the clojure image documentation.docker# Use the official Clojure image. # https://hub.docker.com/_/clojure FROM clojure # Create the project and download dependencies. WORKDIR /usr/src/app COPY project.clj . RUN lein deps # Copy local code to the container image. COPY . . # Build an uberjar release artifact. RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app-standalone.jar # Service must listen to $PORT environment variable. # This default value facilitates local development. ENV PORT 8080 # Run the web service on container startup. CMD ["java", "-jar", "app-standalone.jar"]Create a new file,
service.yamland copy the following service definition
into the file. Make sure to replace{username}with your Docker Hub
username.yamlapiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: helloworld-clojure namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: docker.io/{username}/helloworld-clojure env: - name: TARGET value: "Clojure Sample v1"
Building and deploying the sample
Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app.
Use Docker to build the sample code into a container. To build and push with
Docker Hub, run these commands replacing{username}with your Docker Hub
username:shell# Build the container on your local machine docker build -t {username}/helloworld-clojure . # Push the container to docker registry docker push {username}/helloworld-clojureAfter the build has completed and the container is pushed to docker hub, you
can deploy the app into your cluster. Ensure that the container image value
inservice.yamlmatches the container you built in the previous step. Apply
the configuration usingkubectl:shellkubectl apply --filename service.yamlNow that your service is created, Knative will perform the following steps:
- Create a new immutable revision for this version of the app.
- Network programming to create a route, ingress, service, and load balance
for your app. - Automatically scale your pods up and down (including to zero active pods).
To find the IP address for your service, use these commands to get the
ingress IP for your cluster. If your cluster is new, it may take sometime for
the service to get asssigned an external IP address.shell# In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`. INGRESSGATEWAY=knative-ingressgateway # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x. # Use `istio-ingressgateway` instead, since `knative-ingressgateway` # will be removed in Knative v0.4. if kubectl get configmap config-istio -n knative-serving &> /dev/null; then INGRESSGATEWAY=istio-ingressgateway fi kubectl get svc $INGRESSGATEWAY --namespace istio-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE xxxxxxx-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2dTo find the URL for your service, use
textkubectl get ksvc helloworld-clojure --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain NAME DOMAIN helloworld-clojure helloworld-clojure.default.example.comNow you can make a request to your app to see the results. Replace
{IP_ADDRESS}with the address you see returned in the previous step.shellcurl -H "Host: helloworld-clojure.default.example.com" http://{$IP_ADDRESS} Hello World: Clojure Sample v1!
Removing the sample app deployment
To remove the sample app from your cluster, delete the service record:
kubectl delete --filename service.yamlFile: community/samples/README.md
Sample apps
| Sample Name | Knative Component | Description | Language(s) |
|---|---|---|---|
| Hello World | Serving | A quick introduction that highlights how to deploy an app. | Clojure, Dart, Elixir, Haskell, Rust, Shell, Swift, Vertx |
File: contributing/README.md
Important. Before proceeding, please review the Knative community
Code of Conduct.
If you any have questions or concerns, please contact the authors at
[email protected].
Welcome!
Welcome to the Knative community!
This is the starting point for becoming a contributor - improving code,
improving docs, giving talks, etc.
Other Documents
- Code of Conduct - all contributors must abide by the
code of conduct - Values - shared goals and values for the community
- Contributing to Knative - guidelines and advice on
becoming a contributor - Working Groups - describes our various working groups
- Working Group Processes - describes how
working groups operate - Steering Committee - describes our steering
committee - Technical Oversight Committee - describes our
technical oversight committee - Community Roles - describes the roles individuals can assume
within the Knative community - Reviewing and Merging Pull Requests - how we manage pull
requests - Repository Guidelines - how we create and remove
core repositories
Introduction
Knative is a Kubernetes-based platform to build, deploy, and manage modern
serverless workloads. See Knative docs for in-depth
information about using Knative.
Knative authors
Knative is an open source project with an active development community. The
project was started by Google but has contributions from a growing number of
industry-leading companies. For a current list of the authors, see
Authors.
Authoring samples
Beyond the official documentation there are endless possibilities for combining
tools, platforms, languages, and products. By submitting a tutorial you can
share your experience and help others who are solving similar problems.
Community tutorials are stored in Markdown files under the community folder
Community Samples. These documents are
contributed, reviewed, and maintained by the community.
Submit a Pull Request to the community sample directory under the Knative
component folder that aligns with your document. For example, Knative Serving
samples are under the serving folder. A reviewer will be assigned to review
your submission. They'll work with you to ensure that your submission is clear,
correct, and meets the style guide, but it helps if
you follow it as you write your tutorial.
Meetings and work groups
Knative has public and recorded bi-weekly community meetings.
Each project has one or more working groups driving the
project, and Knative as a single
technical oversight community monitoring the
overall project.
How can I help
If you're looking for something to do to get your feet wet working on Knative,
look for GitHub issues marked with the Help Wanted label:
Even if there's not an issue opened for it, we can always use more testing
throughout the platform. Similarly, we can always use more docs, richer docs,
insightful docs. Or maybe a cool blog post? And if you're a web developer, we
could use your help in spiffing up our public-facing web site.
Questions and issues
If you're a developer, operator, or contributor trying to use Knative, the
following resources are available for you:
For contributors to Knative, we also have
Knative Slack.
Except as otherwise noted, the content of this page is licensed under the
Creative Commons Attribution 4.0 License,
and code samples are licensed under the
Apache 2.0 License.