mirror of https://github.com/knative/docs.git
Convert hello world samples to using Docker (#42)
This commit is contained in:
parent
031584d128
commit
723b407c80
|
@ -1 +1,13 @@
|
||||||
# Samples for knative/serving project
|
# Samples for knative/serving project
|
||||||
|
|
||||||
|
* Hello World - Quick introduction that highlights how to deploy an app using
|
||||||
|
Knative Serving.
|
||||||
|
* [C#](helloworld-csharp/README.md)
|
||||||
|
* [Go](helloworld-go/README.md)
|
||||||
|
* [Java](helloworld-java/README.md)
|
||||||
|
* [Node.js](helloworld-nodejs/README.md)
|
||||||
|
* [PHP](helloworld-php/README.md)
|
||||||
|
* [Python](helloworld-python/README.md)
|
||||||
|
* [Ruby](helloworld-ruby/README.md)
|
||||||
|
* [Rust](helloworld-rust/README.md)
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,11 @@ TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* A Kubernetes Engine cluster with Knative installed. Follow the
|
* A Kubernetes cluster with Knative installed. Follow the
|
||||||
[installation instructions](https://github.com/knative/install/) if you need to create one.
|
[installation instructions](https://github.com/knative/install/) if you need
|
||||||
* The [Google Cloud SDK](https://cloud.google.com/sdk/docs/) is installed and initalized.
|
to create one.
|
||||||
* You have `kubectl` configured to connect to the Kubernetes cluster running Knative. If you created your cluster using the Google Cloud SDK, this has already be done. If you created your cluster from the Google Cloud Console, run the following command, replacing `CLUSTER_NAME` with the name of your cluster:
|
* [Docker](https://www.docker.com) installed and running on your local machine,
|
||||||
```bash
|
and a Docker Hub account configured (we'll use it for a container registry).
|
||||||
gcloud containers clusters get-credentials CLUSTER_NAME
|
|
||||||
```
|
|
||||||
* You have installed [.NET Core SDK 2.1](https://www.microsoft.com/net/core).
|
* You have installed [.NET Core SDK 2.1](https://www.microsoft.com/net/core).
|
||||||
|
|
||||||
## Recreating the sample code
|
## Recreating the sample code
|
||||||
|
@ -28,7 +26,7 @@ recreate the source files from this folder.
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Update the `CreateWebHostBuilder` definition in `Program.cs` by adding
|
1. Update the `CreateWebHostBuilder` definition in `Program.cs` by adding
|
||||||
`.UseUrls("http://0.0.0.0:8080")` to define the serving port:
|
`.UseUrls("http://0.0.0.0:8080")` to define the serving port:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||||
|
@ -36,19 +34,20 @@ recreate the source files from this folder.
|
||||||
.UseStartup<Startup>().UseUrls("http://0.0.0.0:8080");
|
.UseStartup<Startup>().UseUrls("http://0.0.0.0:8080");
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Update the `app.Run(...)` statement in `Startup.cs` to read and return the TARGET environment variable:
|
1. Update the `app.Run(...)` statement in `Startup.cs` to read and return the
|
||||||
|
TARGET environment variable:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
app.Run(async (context) =>
|
app.Run(async (context) =>
|
||||||
{
|
{
|
||||||
var target = Environment.GetEnvironmentVariable("TARGET") ?? "NOT SPECIFIED";
|
var target = Environment.GetEnvironmentVariable("TARGET") ?? "NOT SPECIFIED";
|
||||||
await context.Response.WriteAsync($"Hello World: {target}");
|
await context.Response.WriteAsync($"Hello World: {target}\n");
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
1. In your project directory, create a file named `Dockerfile` and copy the code
|
1. In your project directory, create a file named `Dockerfile` and copy the code
|
||||||
block below into it. For detailed instructions on dockerizing a .NET core app,
|
block below into it. For detailed instructions on dockerizing a .NET core app,
|
||||||
see [dockerizing a .NET core app](https://docs.microsoft.com/en-us/dotnet/core/docker/docker-basics-dotnet-core#dockerize-the-net-core-application).
|
see [dockerizing a .NET core app](https://docs.microsoft.com/en-us/dotnet/core/docker/docker-basics-dotnet-core#dockerize-the-net-core-application).
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
FROM microsoft/dotnet:2.1-sdk
|
FROM microsoft/dotnet:2.1-sdk
|
||||||
|
@ -65,9 +64,7 @@ see [dockerizing a .NET core app](https://docs.microsoft.com/en-us/dotnet/core/d
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a new file, `service.yaml` and copy the following service definition
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
into the file. Make sure to replace `{PROJECT_ID}` with the ID of your Google
|
into the file. Make sure to replace `{username}` with your Docker Hub username.
|
||||||
Cloud project. If you are using docker or another container registry instead,
|
|
||||||
replace the entire image path.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
@ -81,7 +78,7 @@ replace the entire image path.
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-csharp
|
image: docker.io/{username}/helloworld-csharp
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "C# Sample v1"
|
value: "C# Sample v1"
|
||||||
|
@ -92,17 +89,22 @@ replace the entire image path.
|
||||||
Once you have recreated the sample code files (or used the files in 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.
|
folder) you're ready to build and deploy the sample app.
|
||||||
|
|
||||||
1. For this example, we'll use Google Cloud Container Builder to build the
|
1. Use Docker to build the sample code into a container. To build and push with
|
||||||
sample into a container. To use container builder, execute the following gcloud
|
Docker Hub, run these commands replacing `{username}` with your
|
||||||
command:
|
Docker Hub username:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
gcloud container builds submit --tag gcr.io/${PROJECT_ID}/helloworld-csharp
|
# Build the container on your local machine
|
||||||
|
docker build -t {username}/helloworld-csharp .
|
||||||
|
|
||||||
|
# Push the container to docker registry
|
||||||
|
docker push {username}/helloworld-csharp
|
||||||
```
|
```
|
||||||
|
|
||||||
1. After the build has completed, you can deploy the app into your cluster. Ensure
|
1. After the build has completed and the container is pushed to docker hub, you
|
||||||
that the container image value in `service.yaml` matches the container you built in
|
can deploy the app into your cluster. Ensure that the container image value
|
||||||
the previous step. Apply the configuration using `kubectl`:
|
in `service.yaml` matches the container you built in
|
||||||
|
the previous step. Apply the configuration using `kubectl`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl apply -f service.yaml
|
kubectl apply -f service.yaml
|
||||||
|
@ -114,8 +116,8 @@ the previous step. Apply the configuration using `kubectl`:
|
||||||
* Automatically scale your pods up and down (including to zero active pods).
|
* Automatically scale your pods up and down (including to zero active pods).
|
||||||
|
|
||||||
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
||||||
list the ingress points in the cluster. It may take a few seconds for the
|
list the ingress points in the cluster. It may take a few seconds for the
|
||||||
ingress point to be created.
|
ingress point to be created.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl get ing
|
kubectl get ing
|
||||||
|
@ -125,7 +127,7 @@ ingress point to be created.
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Now you can make a request to your app to see the result. Replace
|
1. Now 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.
|
`{IP_ADDRESS}` with the address you see returned in the previous step.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -H "Host: helloworld-csharp.default.demo-domain.com" http://{IP_ADDRESS}
|
curl -H "Host: helloworld-csharp.default.demo-domain.com" http://{IP_ADDRESS}
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace helloworld_csharp
|
||||||
app.Run(async (context) =>
|
app.Run(async (context) =>
|
||||||
{
|
{
|
||||||
var target = Environment.GetEnvironmentVariable("TARGET") ?? "NOT SPECIFIED";
|
var target = Environment.GetEnvironmentVariable("TARGET") ?? "NOT SPECIFIED";
|
||||||
await context.Response.WriteAsync($"Hello World: {target}");
|
await context.Response.WriteAsync($"Hello World: {target}\n");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ spec:
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-csharp
|
image: docker.io/{username}/helloworld-csharp
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "C# Sample v1"
|
value: "C# Sample v1"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Hello World - Go
|
# Hello World - Go sample
|
||||||
|
|
||||||
A simple web app written in Go that you can use for testing.
|
A simple web app written in Go that you can use for testing.
|
||||||
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
||||||
|
@ -6,13 +6,11 @@ TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* A Kubernetes Engine cluster with Knative installed. Follow the
|
* A Kubernetes cluster with Knative installed. Follow the
|
||||||
[installation instructions](https://github.com/knative/install/) if you need to create one.
|
[installation instructions](https://github.com/knative/install/) if you need
|
||||||
* The [Google Cloud SDK](https://cloud.google.com/sdk/docs/) is installed and initalized.
|
to create one.
|
||||||
* You have `kubectl` configured to connect to the Kubernetes cluster running Knative. If you created your cluster using the Google Cloud SDK, this has already be done. If you created your cluster from the Google Cloud Console, run the following command, replacing `CLUSTER_NAME` with the name of your cluster:
|
* [Docker](https://www.docker.com) installed and running on your local machine,
|
||||||
```bash
|
and a Docker Hub account configured (we'll use it for a container registry).
|
||||||
gcloud containers clusters get-credentials CLUSTER_NAME
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recreating the sample code
|
## Recreating the sample code
|
||||||
|
|
||||||
|
@ -21,7 +19,7 @@ apps are generally more useful if you build them step-by-step. The
|
||||||
following instructions recreate the source files from this folder.
|
following instructions recreate the source files from this folder.
|
||||||
|
|
||||||
1. Create a new file named `helloworld.go` and paste the following code. This
|
1. Create a new file named `helloworld.go` and paste the following code. This
|
||||||
code creates a basic web server which listens on port 8080:
|
code creates a basic web server which listens on port 8080:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
@ -53,8 +51,8 @@ code creates a basic web server which listens on port 8080:
|
||||||
```
|
```
|
||||||
|
|
||||||
1. In your project directory, create a file named `Dockerfile` and copy the code
|
1. In your project directory, create a file named `Dockerfile` and copy the code
|
||||||
block below into it. For detailed instructions on dockerizing a Go app, see
|
block below into it. For detailed instructions on dockerizing a Go app, see
|
||||||
[Deploying Go servers with Docker](https://blog.golang.org/docker).
|
[Deploying Go servers with Docker](https://blog.golang.org/docker).
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
# Start from a Debian image with the latest version of Go installed
|
# Start from a Debian image with the latest version of Go installed
|
||||||
|
@ -77,9 +75,7 @@ block below into it. For detailed instructions on dockerizing a Go app, see
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a new file, `service.yaml` and copy the following service definition
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
into the file. Make sure to replace `{PROJECT_ID}` with the ID of your Google
|
into the file. Make sure to replace `{username}` with your Docker Hub username.
|
||||||
Cloud project. If you are using docker or another container registry instead,
|
|
||||||
replace the entire image path.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
@ -93,7 +89,7 @@ replace the entire image path.
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-go
|
image: docker.io/{username}/helloworld-go
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Go Sample v1"
|
value: "Go Sample v1"
|
||||||
|
@ -104,29 +100,35 @@ replace the entire image path.
|
||||||
Once you have recreated the sample code files (or used the files in 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.
|
folder) you're ready to build and deploy the sample app.
|
||||||
|
|
||||||
1. For this example, we'll use Google Cloud Container Builder to build the
|
1. Use Docker to build the sample code into a container. To build and push with
|
||||||
sample into a container. To use container builder, execute the following gcloud
|
Docker Hub, run these commands replacing `{username}` with your
|
||||||
command:
|
Docker Hub username:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
gcloud container builds submit --tag gcr.io/${PROJECT_ID}/helloworld-go
|
# Build the container on your local machine
|
||||||
|
docker build -t {username}/helloworld-go .
|
||||||
|
|
||||||
|
# Push the container to docker registry
|
||||||
|
docker push {username}/helloworld-go
|
||||||
```
|
```
|
||||||
|
|
||||||
1. After the build has completed, you can deploy the app into your cluster.
|
1. After the build has completed and the container is pushed to docker hub, you
|
||||||
Ensure that the container image value in `service.yaml` matches the container
|
can deploy the app into your cluster. Ensure that the container image value
|
||||||
you built in the previous step. Apply the configuration using kubectl:
|
in `service.yaml` matches the container you built in
|
||||||
|
the previous step. Apply the configuration using `kubectl`:
|
||||||
|
|
||||||
```shell kubectl apply -f service.yaml ```
|
```shell
|
||||||
|
kubectl apply -f service.yaml
|
||||||
|
```
|
||||||
|
|
||||||
1. Now that your service is created, Knative will perform the following steps:
|
1. Now that your service is created, Knative will perform the following steps:
|
||||||
* Create a new immutable revision for this version of the app.
|
* Create a new immutable revision for this version of the app.
|
||||||
* Network programming to create a route, ingress, service, and load balancer
|
* Network programming to create a route, ingress, service, and load balance for your app.
|
||||||
for your app.
|
* Automatically scale your pods up and down (including to zero active pods).
|
||||||
* Automatically scale your pods up and down (including to zero active pods).
|
|
||||||
|
|
||||||
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
||||||
list the ingress points in the cluster. It may take a few seconds for the
|
list the ingress points in the cluster. It may take a few seconds for the
|
||||||
ingress point to be created.
|
ingress point to be created.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl get ing
|
kubectl get ing
|
||||||
|
@ -136,7 +138,7 @@ ingress point to be created.
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Now you can make a request to your app to see the results. Replace
|
1. Now 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.
|
`{IP_ADDRESS}` with the address you see returned in the previous step.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -H "Host: helloworld-go.default.demo-domain.com" http://{IP_ADDRESS}
|
curl -H "Host: helloworld-go.default.demo-domain.com" http://{IP_ADDRESS}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2018 Google LLC
|
Copyright 2018 The Knative Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
# Copyright 2018 Google LLC
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
|
||||||
kind: Configuration
|
|
||||||
metadata:
|
|
||||||
name: configuration-example
|
|
||||||
namespace: default
|
|
||||||
spec:
|
|
||||||
revisionTemplate:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
knative.dev/type: app
|
|
||||||
spec:
|
|
||||||
container:
|
|
||||||
# This is the Go import path for the binary to containerize
|
|
||||||
# and substitute here.
|
|
||||||
image: github.com/knative/serving/sample/helloworld
|
|
||||||
env:
|
|
||||||
- name: TARGET
|
|
||||||
value: shiniestnewestversion
|
|
||||||
readinessProbe:
|
|
||||||
httpGet:
|
|
||||||
path: /
|
|
||||||
port: 8080
|
|
||||||
initialDelaySeconds: 3
|
|
||||||
periodSeconds: 3
|
|
||||||
---
|
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
|
||||||
kind: Route
|
|
||||||
metadata:
|
|
||||||
name: route-example
|
|
||||||
namespace: default
|
|
||||||
spec:
|
|
||||||
traffic:
|
|
||||||
- configurationName: configuration-example
|
|
||||||
percent: 100
|
|
|
@ -9,7 +9,7 @@ spec:
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-go
|
image: docker.io/{username}/helloworld-go
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Go Sample v1"
|
value: "Go Sample v1"
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
# Copyright 2018 Google LLC
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
|
||||||
kind: Configuration
|
|
||||||
metadata:
|
|
||||||
name: configuration-example
|
|
||||||
namespace: default
|
|
||||||
spec:
|
|
||||||
revisionTemplate:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
knative.dev/type: app
|
|
||||||
spec:
|
|
||||||
container:
|
|
||||||
# This is the Go import path for the binary to containerize
|
|
||||||
# and substitute here.
|
|
||||||
image: github.com/knative/serving/sample/helloworld
|
|
||||||
env:
|
|
||||||
- name: TARGET
|
|
||||||
value: updatedversion
|
|
||||||
readinessProbe:
|
|
||||||
httpGet:
|
|
||||||
path: /
|
|
||||||
port: 8080
|
|
||||||
initialDelaySeconds: 3
|
|
||||||
periodSeconds: 3
|
|
|
@ -1,18 +1,16 @@
|
||||||
# Hello World - Spring Boot Java sample
|
# Hello World - Spring Boot Java sample
|
||||||
|
|
||||||
A simple web app written in Java using Spring Boot 2.0 that you can use for testing Knative.
|
A simple web app written in Java using Spring Boot 2.0 that you can use for testing.
|
||||||
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
||||||
TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* A Kubernetes Engine cluster with Knative installed. Follow the
|
* A Kubernetes cluster with Knative installed. Follow the
|
||||||
[installation instructions](https://github.com/knative/docs/tree/master/install) if you need to create one.
|
[installation instructions](https://github.com/knative/install/) if you need
|
||||||
* The [Google Cloud SDK](https://cloud.google.com/sdk/docs/) is installed and initalized.
|
to create one.
|
||||||
* You have `kubectl` configured to connect to the Kubernetes cluster running Knative. If you created your cluster using the Google Cloud SDK, this has already be done. If you created your cluster from the Google Cloud Console, run the following command, replacing `CLUSTER_NAME` with the name of your cluster:
|
* [Docker](https://www.docker.com) installed and running on your local machine,
|
||||||
```bash
|
and a Docker Hub account configured (we'll use it for a container registry).
|
||||||
gcloud containers clusters get-credentials CLUSTER_NAME
|
|
||||||
```
|
|
||||||
* You have installed [Java SE 8 or later JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html).
|
* You have installed [Java SE 8 or later JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html).
|
||||||
|
|
||||||
## Recreating the sample code
|
## Recreating the sample code
|
||||||
|
@ -54,28 +52,28 @@ recreate the source files from this folder.
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class HelloworldApplication {
|
public class HelloworldApplication {
|
||||||
|
|
||||||
@Value("${TARGET:NOT SPECIFIED}")
|
@Value("${TARGET:NOT SPECIFIED}")
|
||||||
String target;
|
String target;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
class HelloworldController {
|
class HelloworldController {
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
String hello() {
|
String hello() {
|
||||||
return "Hello World: " + target;
|
return "Hello World: " + target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(HelloworldApplication.class, args);
|
SpringApplication.run(HelloworldApplication.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
1. In your project directory, create a file named `Dockerfile` and copy the code
|
1. In your project directory, create a file named `Dockerfile` and copy the code
|
||||||
block below into it. For detailed instructions on dockerizing a Spring Boot app,
|
block below into it. For detailed instructions on dockerizing a Spring Boot app,
|
||||||
see [Spring Boot with Docker](https://spring.io/guides/gs/spring-boot-docker/).
|
see [Spring Boot with Docker](https://spring.io/guides/gs/spring-boot-docker/).
|
||||||
For additional information on multi-stage docker builds for Java see
|
For additional information on multi-stage docker builds for Java see
|
||||||
[Creating Smaller Java Image using Docker Multi-stage Build](http://blog.arungupta.me/smaller-java-image-docker-multi-stage-build/).
|
[Creating Smaller Java Image using Docker Multi-stage Build](http://blog.arungupta.me/smaller-java-image-docker-multi-stage-build/).
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
FROM maven:3.5-jdk-8-alpine as build
|
FROM maven:3.5-jdk-8-alpine as build
|
||||||
|
@ -90,9 +88,7 @@ For additional information on multi-stage docker builds for Java see
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a new file, `service.yaml` and copy the following service definition
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
into the file. Make sure to replace `{PROJECT_ID}` with the ID of your Google
|
into the file. Make sure to replace `{username}` with your Docker Hub username.
|
||||||
Cloud project. If you are using docker or another container registry instead,
|
|
||||||
replace the entire image path.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
@ -106,7 +102,7 @@ replace the entire image path.
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-java
|
image: docker.io/{username}/helloworld-java
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Spring Boot Sample v1"
|
value: "Spring Boot Sample v1"
|
||||||
|
@ -117,17 +113,22 @@ replace the entire image path.
|
||||||
Once you have recreated the sample code files (or used the files in 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.
|
folder) you're ready to build and deploy the sample app.
|
||||||
|
|
||||||
1. For this example, we'll use Google Cloud Container Builder to build the
|
1. Use Docker to build the sample code into a container. To build and push with
|
||||||
sample into a container. To use container builder, execute the following gcloud
|
Docker Hub, run these commands replacing `{username}` with your
|
||||||
command:
|
Docker Hub username:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
gcloud container builds submit --tag gcr.io/${PROJECT_ID}/helloworld-java
|
# Build the container on your local machine
|
||||||
|
docker build -t {username}/helloworld-java .
|
||||||
|
|
||||||
|
# Push the container to docker registry
|
||||||
|
docker push {username}/helloworld-java
|
||||||
```
|
```
|
||||||
|
|
||||||
1. After the build has completed, you can deploy the app into your cluster. Ensure
|
1. After the build has completed and the container is pushed to docker hub, you
|
||||||
that the container image value in `service.yaml` matches the container you built in
|
can deploy the app into your cluster. Ensure that the container image value
|
||||||
the previous step. Apply the configuration using `kubectl`:
|
in `service.yaml` matches the container you built in
|
||||||
|
the previous step. Apply the configuration using `kubectl`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl apply -f service.yaml
|
kubectl apply -f service.yaml
|
||||||
|
@ -139,8 +140,8 @@ the previous step. Apply the configuration using `kubectl`:
|
||||||
* Automatically scale your pods up and down (including to zero active pods).
|
* Automatically scale your pods up and down (including to zero active pods).
|
||||||
|
|
||||||
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
||||||
list the ingress points in the cluster. It may take a few seconds for the
|
list the ingress points in the cluster. It may take a few seconds for the
|
||||||
ingress point to be created.
|
ingress point to be created.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl get ing
|
kubectl get ing
|
||||||
|
@ -150,7 +151,7 @@ ingress point to be created.
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Now you can make a request to your app to see the result. Replace
|
1. Now 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.
|
`{IP_ADDRESS}` with the address you see returned in the previous step.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -H "Host: helloworld-java.default.demo-domain.com" http://{IP_ADDRESS}
|
curl -H "Host: helloworld-java.default.demo-domain.com" http://{IP_ADDRESS}
|
||||||
|
|
|
@ -9,7 +9,7 @@ spec:
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-java
|
image: docker.io/{username}/helloworld-java
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Spring Boot Sample v1"
|
value: "Spring Boot Sample v1"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Hello World - Node.js
|
# Hello World - Node.js sample
|
||||||
|
|
||||||
A simple web app written in Node.js that you can use for testing.
|
A simple web app written in Node.js that you can use for testing.
|
||||||
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
||||||
|
@ -6,16 +6,11 @@ TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* A Kubernetes Engine cluster with Knative installed. Follow the
|
* A Kubernetes cluster with Knative installed. Follow the
|
||||||
[installation instructions](https://github.com/knative/install/) if you need to create one.
|
[installation instructions](https://github.com/knative/install/) if you need
|
||||||
* The [Google Cloud SDK](https://cloud.google.com/sdk/docs/) is installed and initalized.
|
to create one.
|
||||||
* You have `kubectl` configured to connect to the Kubernetes cluster running Knative.
|
* [Docker](https://www.docker.com) installed and running on your local machine,
|
||||||
If you created your cluster using the Google Cloud SDK, this has already be done. If you
|
and a Docker Hub account configured (we'll use it for a container registry).
|
||||||
created your cluster from the Google Cloud Console, run the following command, replacing
|
|
||||||
`CLUSTER_NAME` with the name of your cluster:
|
|
||||||
```bash
|
|
||||||
gcloud containers clusters get-credentials CLUSTER_NAME
|
|
||||||
```
|
|
||||||
* [Node.js](https://nodejs.org/en/) installed and configured.
|
* [Node.js](https://nodejs.org/en/) installed and configured.
|
||||||
|
|
||||||
## Recreating the sample code
|
## Recreating the sample code
|
||||||
|
@ -24,7 +19,9 @@ 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
|
generally more useful if you build them step-by-step. The following instructions
|
||||||
recreate the source files from this folder.
|
recreate the source files from this folder.
|
||||||
|
|
||||||
1. Create a new directory and initalize `npm`. You can accept the defaults, but change the entry point to `app.js` to be consistent with the sample code here.
|
1. Create a new directory and initalize `npm`. You can accept the defaults,
|
||||||
|
but change the entry point to `app.js` to be consistent with the sample
|
||||||
|
code here.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
npm init
|
npm init
|
||||||
|
@ -40,7 +37,7 @@ recreate the source files from this folder.
|
||||||
license: (ISC) Apache-2.0
|
license: (ISC) Apache-2.0
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Install the `express` dependency:
|
1. Install the `express` package:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
npm install express --save
|
npm install express --save
|
||||||
|
@ -82,7 +79,9 @@ recreate the source files from this folder.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
1. In your project directory, create a file named `Dockerfile` and paste the following code. For detailed instructions on dockerizing a Node.js app, see [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/).
|
1. In your project directory, create a file named `Dockerfile` and copy the code
|
||||||
|
block below into it. For detailed instructions on dockerizing a Node.js app,
|
||||||
|
see [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/).
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
FROM node:8
|
FROM node:8
|
||||||
|
@ -106,10 +105,8 @@ recreate the source files from this folder.
|
||||||
CMD [ "npm", "start" ]
|
CMD [ "npm", "start" ]
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a new file, `service.yaml` and copy the following service
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
definitioninto the file. Make sure to replace `{PROJECT_ID}` with the ID of your
|
into the file. Make sure to replace `{username}` with your Docker Hub username.
|
||||||
Google Cloud project. If you are using docker or another container registry
|
|
||||||
instead, replace the entire image path.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
@ -123,7 +120,7 @@ instead, replace the entire image path.
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-nodejs
|
image: docker.io/{username}/helloworld-nodejs
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Node.js Sample v1"
|
value: "Node.js Sample v1"
|
||||||
|
@ -134,17 +131,22 @@ instead, replace the entire image path.
|
||||||
Once you have recreated the sample code files (or used the files in 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.
|
folder) you're ready to build and deploy the sample app.
|
||||||
|
|
||||||
1. For this example, we'll use Google Cloud Container Builder to build the
|
1. Use Docker to build the sample code into a container. To build and push with
|
||||||
sample into a container. To use container builder, execute the following gcloud
|
Docker Hub, run these commands replacing `{username}` with your
|
||||||
command:
|
Docker Hub username:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
gcloud container builds submit --tag gcr.io/${PROJECT_ID}/helloworld-nodejs
|
# Build the container on your local machine
|
||||||
|
docker build -t {username}/helloworld-nodejs .
|
||||||
|
|
||||||
|
# Push the container to docker registry
|
||||||
|
docker push {username}/helloworld-nodejs
|
||||||
```
|
```
|
||||||
|
|
||||||
1. After the build has completed, you can deploy the app into your cluster.
|
1. After the build has completed and the container is pushed to docker hub, you
|
||||||
Ensure that the container image value in `service.yaml` matches the container
|
can deploy the app into your cluster. Ensure that the container image value
|
||||||
you built in the previous step. Apply the configuration using kubectl:
|
in `service.yaml` matches the container you built in
|
||||||
|
the previous step. Apply the configuration using `kubectl`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl apply -f service.yaml
|
kubectl apply -f service.yaml
|
||||||
|
@ -156,8 +158,8 @@ you built in the previous step. Apply the configuration using kubectl:
|
||||||
* Automatically scale your pods up and down (including to zero active pods).
|
* Automatically scale your pods up and down (including to zero active pods).
|
||||||
|
|
||||||
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
||||||
list the ingress points in the cluster. It may take a few seconds for the
|
list the ingress points in the cluster. It may take a few seconds for the
|
||||||
ingress point to be created.
|
ingress point to be created.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl get ing
|
kubectl get ing
|
||||||
|
@ -167,7 +169,7 @@ ingress point to be created.
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Now you can make a request to your app to see the result. Replace
|
1. Now 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.
|
`{IP_ADDRESS}` with the address you see returned in the previous step.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -H "Host: helloworld-nodejs.default.demo-domain.com" http://{IP_ADDRESS}
|
curl -H "Host: helloworld-nodejs.default.demo-domain.com" http://{IP_ADDRESS}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2018 Google LLC
|
Copyright 2018 The Knative Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -9,7 +9,7 @@ spec:
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-nodejs
|
image: docker.io/{username}/helloworld-nodejs
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Node.js Sample v1"
|
value: "Node.js Sample v1"
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
# Hello World - PHP
|
# Hello World - PHP sample
|
||||||
|
|
||||||
A simple web app written in PHP that you can use for testing.application in PHP.
|
A simple web app written in PHP that you can use for testing.
|
||||||
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}". If
|
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}". If
|
||||||
TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* A Kubernetes Engine cluster with Knative installed. Follow the
|
* A Kubernetes cluster with Knative installed. Follow the
|
||||||
[installation instructions](https://github.com/knative/install/) if you need to create one.
|
[installation instructions](https://github.com/knative/install/) if you need
|
||||||
* The [Google Cloud SDK](https://cloud.google.com/sdk/docs/) is installed and initalized.
|
to create one.
|
||||||
* You have `kubectl` configured to connect to the Kubernetes cluster running Knative. If you created your cluster using the Google Cloud SDK, this has already be done. If you created your cluster from the Google Cloud Console, run the following command, replacing `CLUSTER_NAME` with the name of your cluster:
|
* [Docker](https://www.docker.com) installed and running on your local machine,
|
||||||
|
and a Docker Hub account configured (we'll use it for a container registry).
|
||||||
```bash
|
|
||||||
gcloud containers clusters get-credentials CLUSTER_NAME
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recreating the sample code
|
## Recreating the sample code
|
||||||
|
|
||||||
|
@ -22,10 +19,12 @@ apps are generally more useful if you build them step-by-step. The
|
||||||
following instructions recreate the source files from this folder.
|
following instructions recreate the source files from this folder.
|
||||||
|
|
||||||
1. Create a new directory and cd into it:
|
1. Create a new directory and cd into it:
|
||||||
|
|
||||||
````shell
|
````shell
|
||||||
mkdir app
|
mkdir app
|
||||||
cd app
|
cd app
|
||||||
````
|
````
|
||||||
|
|
||||||
1. Create a file named `index.php` and copy the code block below into it:
|
1. Create a file named `index.php` and copy the code block below into it:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
@ -36,7 +35,7 @@ following instructions recreate the source files from this folder.
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a file named `Dockerfile` and copy the code block below into it.
|
1. Create a file named `Dockerfile` and copy the code block below into it.
|
||||||
See [official PHP docker image](https://hub.docker.com/_/php/) for more details.
|
See [official PHP docker image](https://hub.docker.com/_/php/) for more details.
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
FROM php:7.2.6-apache
|
FROM php:7.2.6-apache
|
||||||
|
@ -47,9 +46,8 @@ See [official PHP docker image](https://hub.docker.com/_/php/) for more details.
|
||||||
RUN sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf
|
RUN sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a file named `service.yaml` and copy the following service definition into the file.
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
Make sure to replace `{PROJECT_ID}` with the ID of your Google Cloud project.
|
into the file. Make sure to replace `{username}` with your Docker Hub username.
|
||||||
If you are using docker or another container registry instead, replace the entire image path.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
@ -63,7 +61,7 @@ If you are using docker or another container registry instead, replace the entir
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-php
|
image: docker.io/{username}/helloworld-php
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "PHP Sample v1"
|
value: "PHP Sample v1"
|
||||||
|
@ -74,16 +72,22 @@ If you are using docker or another container registry instead, replace the entir
|
||||||
Once you have recreated the sample code files (or used the files in the sample folder)
|
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.
|
you're ready to build and deploy the sample app.
|
||||||
|
|
||||||
1. For this example, we'll use Google Cloud Container Builder to build the sample into a container.
|
1. Use Docker to build the sample code into a container. To build and push with
|
||||||
To use container builder, execute the following gcloud command:
|
Docker Hub, run these commands replacing `{username}` with your
|
||||||
|
Docker Hub username:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
gcloud container builds submit --tag gcr.io/${PROJECT_ID}/helloworld-php
|
# Build the container on your local machine
|
||||||
|
docker build -t {username}/helloworld-php .
|
||||||
|
|
||||||
|
# Push the container to docker registry
|
||||||
|
docker push {username}/helloworld-php
|
||||||
```
|
```
|
||||||
|
|
||||||
1. After the build has completed, you can deploy the app into your cluster.
|
1. After the build has completed and the container is pushed to docker hub, you
|
||||||
Ensure that the container image value in `service.yaml` matches the container
|
can deploy the app into your cluster. Ensure that the container image value
|
||||||
you build in the previous step. Apply the configuration using kubectl:
|
in `service.yaml` matches the container you built in
|
||||||
|
the previous step. Apply the configuration using `kubectl`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl apply -f service.yaml
|
kubectl apply -f service.yaml
|
||||||
|
@ -103,8 +107,8 @@ you build in the previous step. Apply the configuration using kubectl:
|
||||||
helloworld-php-ingress helloworld-php.default.demo-domain.com,*.helloworld-php.default.demo-domain.com 35.232.134.1 80 1m
|
helloworld-php-ingress helloworld-php.default.demo-domain.com,*.helloworld-php.default.demo-domain.com 35.232.134.1 80 1m
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Now you can make a request to your app to see the result. Replace `{IP_ADDRESS}`
|
1. Now you can make a request to your app to see the result. Replace
|
||||||
with the address you see returned in the previous step.
|
`{IP_ADDRESS}` with the address you see returned in the previous step.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -H "Host: helloworld-php.default.demo-domain.com" http://{IP_ADDRESS}
|
curl -H "Host: helloworld-php.default.demo-domain.com" http://{IP_ADDRESS}
|
||||||
|
|
|
@ -9,7 +9,7 @@ spec:
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-php
|
image: docker.io/{username}/helloworld-php
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "PHP Sample v1"
|
value: "PHP Sample v1"
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
# Hello World - Python sample
|
# Hello World - Python sample
|
||||||
|
|
||||||
This sample application shows how to create a hello world application in Python.
|
A simple web app written in Python that you can use for testing.
|
||||||
When called, this application reads an env variable 'TARGET'
|
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
||||||
and prints "Hello World: ${TARGET}!".
|
TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
||||||
If TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* You have a Kubernetes cluster with Knative installed.
|
* A Kubernetes cluster with Knative installed. Follow the
|
||||||
Follow the [installation instructions](https://github.com/knative/install/) if you need to do this.
|
[installation instructions](https://github.com/knative/install/) if you need
|
||||||
* You have installed and initialized [Google Cloud SDK](https://cloud.google.com/sdk/docs/)
|
to create one.
|
||||||
and have created a project in Google Cloud.
|
* [Docker](https://www.docker.com) installed and running on your local machine,
|
||||||
* You have `kubectl` configured to connect to the Kubernetes cluster running Knative.
|
and a Docker Hub account configured (we'll use it for a container registry).
|
||||||
|
|
||||||
## Steps to recreate the sample code
|
## Steps to recreate the sample code
|
||||||
|
|
||||||
|
@ -20,6 +19,7 @@ generally more useful if you build them step-by-step.
|
||||||
The following instructions recreate the source files from this folder.
|
The following instructions recreate the source files from this folder.
|
||||||
|
|
||||||
1. Create a new directory and cd into it:
|
1. Create a new directory and cd into it:
|
||||||
|
|
||||||
````shell
|
````shell
|
||||||
mkdir app
|
mkdir app
|
||||||
cd app
|
cd app
|
||||||
|
@ -43,7 +43,7 @@ The following instructions recreate the source files from this folder.
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a file named `Dockerfile` and copy the code block below into it.
|
1. Create a file named `Dockerfile` and copy the code block below into it.
|
||||||
See [official Python docker image](https://hub.docker.com/_/python/) for more details.
|
See [official Python docker image](https://hub.docker.com/_/python/) for more details.
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
FROM python
|
FROM python
|
||||||
|
@ -58,9 +58,8 @@ See [official Python docker image](https://hub.docker.com/_/python/) for more de
|
||||||
CMD ["app.py"]
|
CMD ["app.py"]
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a file named `service.yaml` and copy the following service definition into the file.
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
Make sure to replace `{PROJECT_ID}` with the ID of your Google Cloud project.
|
into the file. Make sure to replace `{username}` with your Docker Hub username.
|
||||||
If you are using docker or another container registry instead, replace the entire image path.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
@ -74,7 +73,7 @@ If you are using docker or another container registry instead, replace the entir
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-python
|
image: docker.io/{username}/helloworld-python
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Python Sample v1"
|
value: "Python Sample v1"
|
||||||
|
@ -82,20 +81,25 @@ If you are using docker or another container registry instead, replace the entir
|
||||||
|
|
||||||
## Build and deploy this sample
|
## Build and deploy this sample
|
||||||
|
|
||||||
Once you have recreated the sample code files (or used the files in the sample folder)
|
Once you have recreated the sample code files (or used the files in the sample
|
||||||
you're ready to build and deploy the sample app.
|
folder) you're ready to build and deploy the sample app.
|
||||||
|
|
||||||
1. For this example, we'll use Google Cloud Container Builder to build the sample into a container.
|
1. Use Docker to build the sample code into a container. To build and push with
|
||||||
To use container builder, execute the following gcloud command. Make sure to replace `${PROJECT_ID}`
|
Docker Hub, run these commands replacing `{username}` with your
|
||||||
with the ID of your Google Cloud project.
|
Docker Hub username:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
gcloud container builds submit --tag gcr.io/${PROJECT_ID}/helloworld-python
|
# Build the container on your local machine
|
||||||
|
docker build -t {username}/helloworld-python .
|
||||||
|
|
||||||
|
# Push the container to docker registry
|
||||||
|
docker push {username}/helloworld-python
|
||||||
```
|
```
|
||||||
|
|
||||||
1. After the build has completed, you can deploy the app into your cluster.
|
1. After the build has completed and the container is pushed to docker hub, you
|
||||||
Ensure that the container image value in `service.yaml` matches the container you build in the previous step.
|
can deploy the app into your cluster. Ensure that the container image value
|
||||||
Apply the configuration using kubectl:
|
in `service.yaml` matches the container you built in
|
||||||
|
the previous step. Apply the configuration using `kubectl`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl apply -f service.yaml
|
kubectl apply -f service.yaml
|
||||||
|
@ -116,7 +120,7 @@ Apply the configuration using kubectl:
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Now you can make a request to your app to see the result. Replace `{IP_ADDRESS}`
|
1. Now 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.
|
with the address you see returned in the previous step.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -H "Host: helloworld-python.default.demo-domain.com" http://{IP_ADDRESS}
|
curl -H "Host: helloworld-python.default.demo-domain.com" http://{IP_ADDRESS}
|
||||||
|
|
|
@ -9,7 +9,7 @@ spec:
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-python
|
image: docker.io/{username}/helloworld-python
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Python Sample v1"
|
value: "Python Sample v1"
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
# Hello World - Ruby sample
|
# Hello World - Ruby sample
|
||||||
|
|
||||||
This sample application shows how to create a hello world application in Ruby.
|
A simple wenb app written in Ruby that you can use for testing.
|
||||||
When called, this application reads an env variable 'TARGET'
|
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
||||||
and prints "Hello World: ${TARGET}!".
|
TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
||||||
If TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* You have a Kubernetes cluster with Knative installed.
|
* A Kubernetes cluster with Knative installed. Follow the
|
||||||
Follow the [installation instructions](https://github.com/knative/install/) if you need to do this.
|
[installation instructions](https://github.com/knative/install/) if you need
|
||||||
* You have installed and initialized [Google Cloud SDK](https://cloud.google.com/sdk/docs/)
|
to create one.
|
||||||
and have created a project in Google Cloud.
|
* [Docker](https://www.docker.com) installed and running on your local machine,
|
||||||
* You have `kubectl` configured to connect to the Kubernetes cluster running Knative.
|
and a Docker Hub account configured (we'll use it for a container registry).
|
||||||
|
|
||||||
## Steps to recreate the sample code
|
## Steps to recreate the sample code
|
||||||
|
|
||||||
|
@ -20,10 +19,12 @@ generally more useful if you build them step-by-step.
|
||||||
The following instructions recreate the source files from this folder.
|
The following instructions recreate the source files from this folder.
|
||||||
|
|
||||||
1. Create a new directory and cd into it:
|
1. Create a new directory and cd into it:
|
||||||
|
|
||||||
````shell
|
````shell
|
||||||
mkdir app
|
mkdir app
|
||||||
cd app
|
cd app
|
||||||
````
|
````
|
||||||
|
|
||||||
1. Create a file named `app.rb` and copy the code block below into it:
|
1. Create a file named `app.rb` and copy the code block below into it:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
@ -38,7 +39,7 @@ The following instructions recreate the source files from this folder.
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a file named `Dockerfile` and copy the code block below into it.
|
1. Create a file named `Dockerfile` and copy the code block below into it.
|
||||||
See [official Ruby docker image](https://hub.docker.com/_/ruby/) for more details.
|
See [official Ruby docker image](https://hub.docker.com/_/ruby/) for more details.
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
FROM ruby
|
FROM ruby
|
||||||
|
@ -59,23 +60,21 @@ See [official Ruby docker image](https://hub.docker.com/_/ruby/) for more detail
|
||||||
|
|
||||||
1. Create a file named `Gemfile` and copy the text block below into it.
|
1. Create a file named `Gemfile` and copy the text block below into it.
|
||||||
|
|
||||||
```
|
```gem
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
gem 'sinatra'
|
gem 'sinatra'
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Run:
|
1. Run bundle. If you don't have bundler installed, copy the
|
||||||
|
[Gemfile.lock](./Gemfile.lock) to your working directory.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
bundle install
|
bundle install
|
||||||
```
|
```
|
||||||
|
|
||||||
If you don't have bundler installed, copy the [Gemfile.lock](./Gemfile.lock) to your working directory.
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
|
into the file. Make sure to replace `{username}` with your Docker Hub username.
|
||||||
1. Create a file named `service.yaml` and copy the following service definition into the file.
|
|
||||||
Make sure to replace `{PROJECT_ID}` with the ID of your Google Cloud project.
|
|
||||||
If you are using docker or another container registry instead, replace the entire image path.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
@ -89,7 +88,7 @@ If you are using docker or another container registry instead, replace the entir
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-ruby
|
image: docker.io/{username}/helloworld-ruby
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Ruby Sample v1"
|
value: "Ruby Sample v1"
|
||||||
|
@ -100,17 +99,22 @@ If you are using docker or another container registry instead, replace the entir
|
||||||
Once you have recreated the sample code files (or used the files in the sample folder)
|
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.
|
you're ready to build and deploy the sample app.
|
||||||
|
|
||||||
1. For this example, we'll use Google Cloud Container Builder to build the sample into a container.
|
1. Use Docker to build the sample code into a container. To build and push with
|
||||||
To use container builder, execute the following gcloud command. Make sure to replace `${PROJECT_ID}`
|
Docker Hub, run these commands replacing `{username}` with your
|
||||||
with the ID of your Google Cloud project.
|
Docker Hub username:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
gcloud container builds submit --tag gcr.io/${PROJECT_ID}/helloworld-ruby
|
# Build the container on your local machine
|
||||||
|
docker build -t {username}/helloworld-ruby .
|
||||||
|
|
||||||
|
# Push the container to docker registry
|
||||||
|
docker push {username}/helloworld-ruby
|
||||||
```
|
```
|
||||||
|
|
||||||
1. After the build has completed, you can deploy the app into your cluster.
|
1. After the build has completed and the container is pushed to docker hub, you
|
||||||
Ensure that the container image value in `service.yaml` matches the container you build in the previous step.
|
can deploy the app into your cluster. Ensure that the container image value
|
||||||
Apply the configuration using kubectl:
|
in `service.yaml` matches the container you built in
|
||||||
|
the previous step. Apply the configuration using `kubectl`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl apply -f service.yaml
|
kubectl apply -f service.yaml
|
||||||
|
@ -131,7 +135,7 @@ Apply the configuration using kubectl:
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Now you can make a request to your app to see the result. Replace `{IP_ADDRESS}`
|
1. Now 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.
|
with the address you see returned in the previous step.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -H "Host: helloworld-ruby.default.demo-domain.com" http://{IP_ADDRESS}
|
curl -H "Host: helloworld-ruby.default.demo-domain.com" http://{IP_ADDRESS}
|
||||||
|
|
|
@ -9,7 +9,7 @@ spec:
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-ruby
|
image: docker.io/{username}/helloworld-ruby
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Ruby Sample v1"
|
value: "Ruby Sample v1"
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
# Hello World -Rust
|
# Hello World - Rust sample
|
||||||
|
|
||||||
A simple web app in Rust that you can use for testing.
|
A simple web app written in Rust that you can use for testing.
|
||||||
It reads in an env variable 'TARGET' and prints "Hello World: ${TARGET}" if
|
It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If
|
||||||
TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* You have a Kubernetes cluster with Knative installed. Follow the [installation instructions](https://github.com/knative/install/) if you need to do this.
|
* A Kubernetes cluster with Knative installed. Follow the
|
||||||
* You have installed and initalized [Google Cloud SDK](https://cloud.google.com/sdk/docs/) and have created a project in Google Cloud.
|
[installation instructions](https://github.com/knative/install/) if you need
|
||||||
* You have `kubectl` configured to connect to the Kubernetes cluster running Knative.
|
to create one.
|
||||||
|
* [Docker](https://www.docker.com) 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
|
## Steps to recreate the sample code
|
||||||
|
|
||||||
|
@ -16,7 +18,7 @@ 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
|
apps are generally more useful if you build them step-by-step. The
|
||||||
following instructions recreate the source files from this folder.
|
following instructions recreate the source files from this folder.
|
||||||
|
|
||||||
1. Create a new file named `Cargo.toml` and paste the following code. This code
|
1. Create a new file named `Cargo.toml` and paste the following code:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[package]
|
[package]
|
||||||
|
@ -29,7 +31,9 @@ following instructions recreate the source files from this folder.
|
||||||
pretty_env_logger = "0.2.3"
|
pretty_env_logger = "0.2.3"
|
||||||
```
|
```
|
||||||
|
|
||||||
1. In an `src` folder, Create a new file named `main.rs` and paste the following code. This code creates a basic web server which listens on port 8080:
|
1. Create a `src` folder, then create a new file named `main.rs` in that folder
|
||||||
|
and paste the following code. This code creates a basic web server which
|
||||||
|
listens on port 8080:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
@ -69,7 +73,8 @@ following instructions recreate the source files from this folder.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
1. In your project directory, create a file named `Dockerfile`.
|
1. In your project directory, create a file named `Dockerfile` and copy the code
|
||||||
|
block below into it.
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
FROM rust:1.27.0
|
FROM rust:1.27.0
|
||||||
|
@ -84,7 +89,8 @@ following instructions recreate the source files from this folder.
|
||||||
CMD ["hellorust"]
|
CMD ["hellorust"]
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{PROJECT_ID}` with the ID of your Google Cloud project. If you are using docker or another container registry instead, replace the entire image path.
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
|
into the file. Make sure to replace `{username}` with your Docker Hub username.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
@ -98,7 +104,7 @@ following instructions recreate the source files from this folder.
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-rust
|
image: docker.io/{username}/helloworld-rust
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Rust Sample v1"
|
value: "Rust Sample v1"
|
||||||
|
@ -106,17 +112,25 @@ following instructions recreate the source files from this folder.
|
||||||
|
|
||||||
## Build and deploy this sample
|
## 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.
|
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.
|
||||||
|
|
||||||
1. Clone this repository and navigate into the `serving/samples/helloworld-rust` directory.
|
1. Use Docker to build the sample code into a container. To build and push with
|
||||||
|
Docker Hub, run these commands replacing `{username}` with your
|
||||||
1. For this example, we'll use Google Cloud Container Builder to build the sample into a container. To use container builder, execute the following gcloud command:
|
Docker Hub username:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
gcloud container builds submit --tag gcr.io/${PROJECT_ID}/helloworld-rust
|
# Build the container on your local machine
|
||||||
|
docker build -t {username}/helloworld-rust .
|
||||||
|
|
||||||
|
# Push the container to docker registry
|
||||||
|
docker push {username}/helloworld-rust
|
||||||
```
|
```
|
||||||
|
|
||||||
1. After the build has completed, you can deploy the app into your cluster. Ensure that the container image value in `service.yaml` matches the container you build in the previous step. Apply the configuration using kubectl:
|
1. After 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 `service.yaml` matches the container you built in
|
||||||
|
the previous step. Apply the configuration using `kubectl`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl apply -f service.yaml
|
kubectl apply -f service.yaml
|
||||||
|
@ -127,23 +141,26 @@ Once you have recreated the sample code files (or used the files in the sample f
|
||||||
* Network programming to create a route, ingress, service, and load balance for your 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).
|
* Automatically scale your pods up and down (including to zero active pods).
|
||||||
|
|
||||||
1. To find the URL and IP address for your service, use kubectl to list the ingress points in the cluster. You may need to wait a few seconds for the ingress point to be created, if you don't see it right away.
|
1. To find the URL and IP address for your service, use `kubectl get ing` to
|
||||||
|
list the ingress points in the cluster. It may take a few seconds for the
|
||||||
|
ingress point to be created.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl get ing --watch
|
kubectl get ing
|
||||||
|
|
||||||
NAME HOSTS ADDRESS PORTS AGE
|
NAME HOSTS ADDRESS PORTS AGE
|
||||||
helloworld-rust-ingress helloworld-rust.default.demo-domain.com 35.232.134.1 80 1m
|
helloworld-rust-ingress helloworld-rust.default.demo-domain.com 35.232.134.1 80 1m
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Now 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.
|
1. Now 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.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -H "Host: helloworld-rust.default.demo-domain.com" http://{IP_ADDRESS}
|
curl -H "Host: helloworld-rust.default.demo-domain.com" http://{IP_ADDRESS}
|
||||||
Hello World: NOT SPECIFIED
|
Hello World!
|
||||||
```
|
```
|
||||||
|
|
||||||
## Remove the sample app deployment
|
## Removing the sample app deployment
|
||||||
|
|
||||||
To remove the sample app from your cluster, delete the service record:
|
To remove the sample app from your cluster, delete the service record:
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ spec:
|
||||||
revisionTemplate:
|
revisionTemplate:
|
||||||
spec:
|
spec:
|
||||||
container:
|
container:
|
||||||
image: gcr.io/{PROJECT_ID}/helloworld-rust
|
image: docker.io/{username}/helloworld-rust
|
||||||
env:
|
env:
|
||||||
- name: TARGET
|
- name: TARGET
|
||||||
value: "Rust Sample v1"
|
value: "Rust Sample v1"
|
||||||
|
|
Loading…
Reference in New Issue