Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
toshi0607 committed Oct 20, 2019
1 parent 12f6277 commit ea89c0a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 27 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# build-your-own-platform-with-knative
# Knativeで作るDIY FaaS

![](./images/knative.png)

## ワークショップ

Expand All @@ -13,5 +15,5 @@
| 1 | [各コンポーネントの理解](step1.md) | プラットフォーム |
| 2 | [Knativeベースのプラットフォーム利用](step2.md) | 開発者 |
| 3 | [DIY FaaS Platform](step3.md) | プラットフォーム |
| 4 | [Knativeベースのプラットフォーム利用](step4.md) | 開発者 |
| 4 | [Knativeベースのマネージドサービス利用](step4.md) | 開発者 |
| 5 | [参考情報](step5.md) | - |
Binary file added images/eventing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/knative.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 15 additions & 8 deletions step0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Kubernetes

本ハンズオンは基本的にGCPを利用します。Google Cloud Shell上でコマンドを実行し、Google Kubernetes Engine(GKE)上にKubernetesクラスタを準備します。
本ワークショップでは基本的にGCPを利用します。Google Cloud Shell上でコマンドを実行し、Google Kubernetes Engine(GKE)上にKubernetesクラスタを準備します。

ローカル環境のターミナルからローカル環境にKubernetesクラスタを構築することももちろん可能です。しかし、本ハンズオンでは準備を容易にし、Knativeを学ぶことに一層集中していただくためにCloud ShellとGKEの利用を推奨します。
ローカル環境のターミナルからローカル環境にKubernetesクラスタを構築することももちろん可能です。しかし、本ワークショップでは準備を容易にし、Knativeを学ぶことに一層集中していただくためにCloud ShellとGKEの利用を推奨します。

つぎの環境を準備していきます。

Expand All @@ -27,7 +27,7 @@ https://cloud.google.com/free/docs/frequently-asked-questions?hl=ja

### GCPプロジェクト

GKEでKubernetesクラスタを構築するプロジェクトを作成します。本ハンズオン用に利用できるプロジェクトがすでにある場合はスキップして大丈夫です
GKEでKubernetesクラスタを構築するプロジェクトを作成します。本ワークショップ用に利用できるプロジェクトがすでにある場合はスキップして大丈夫です

ダッシュボードで*作成*をクリックしてください。

Expand Down Expand Up @@ -97,14 +97,18 @@ $ gcloud services enable \
```shell
$ gcloud beta container clusters create $CLUSTER_NAME \
--addons=HorizontalPodAutoscaling,HttpLoadBalancing,Istio \
--machine-type=n1-standard-4 \
--machine-type=n1-standard-2 \
--cluster-version=latest --zone=$CLUSTER_ZONE \
--enable-stackdriver-kubernetes --enable-ip-alias \
--enable-autoscaling --min-nodes=1 --max-nodes=5 \
--enable-autorepair \
--scopes cloud-platform
```

作成には少し時間がかかります。つぎのURLから作成状況が確認できます。

https://console.cloud.google.com/kubernetes/list

つぎのコマンドを実行して現在のユーザーにcluster-adminロールを付与してください。

```shell
Expand All @@ -113,10 +117,6 @@ $ kubectl create clusterrolebinding cluster-admin-binding \
--user=$(gcloud config get-value core/account)
```

作成には少し時間がかかります。つぎのURLから作成状況が確認できます。

https://console.cloud.google.com/kubernetes/list

つぎのコマンドを実行してノードの準備ができていることを確認してください。

```shell
Expand Down Expand Up @@ -153,6 +153,13 @@ EventingでKnativeのServiceをsinkに指定する場合は現状追加でセッ

```
$ kubectl apply -f https://raw.githubusercontent.com/knative/serving/master/third_party/istio-1.2.7/istio-knative-extras.yaml
# Istioのバージョン確認
# $ kubectl get pod -n istio-system
# istio-ingressgateway-f659695c4-sssrs
# $ kubectl get pod istio-ingressgateway-f659695c4-sssrs -n istio-system -oyaml | grep image
# image: gke.gcr.io/istio/proxyv2:1.1.13-gke.0
# => OK: 1.2.7, NG: 1.3.3
```

cf. [issue#1973](https://github.com/knative/eventing/issues/1973)
Expand Down
25 changes: 16 additions & 9 deletions step1.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ $ kubectl get configurations blue-green-demo -o=jsonpath='{.status.latestCreated
blue-green-demo-66h62 # 人によって異なります。
```

つぎのマニフェストを`blue-green-route.yaml`という名前で保存してください`spec.traffic[0].revisionName`は上で取得したもので置き換えが必要です。
つぎのマニフェストを`blue-green-route.yaml`という名前で保存し、適用してください`spec.traffic[0].revisionName`は上で取得したもので置き換えが必要です。

```yaml
apiVersion: serving.knative.dev/v1alpha1
Expand All @@ -248,6 +248,10 @@ spec:

```

```shell
$ kubectl apply --filename blue-green-route.yaml
```

アクセスしてみると、何度リクエストしても`Hello blue!`が出力されすはずです。

```
Expand Down Expand Up @@ -294,7 +298,7 @@ blue-green-demo-zdjbc # 人によって異なります。

新しく作成したRevisionへアクセスできるようにしてみましょう。

`blue-green-route.yaml`をつぎのように変更して保存してください
`blue-green-route.yaml`をつぎのように変更して保存し、適用てください

```yaml
apiVersion: serving.knative.dev/v1alpha1
Expand All @@ -311,9 +315,13 @@ spec:
tag: v2
```
```shell
$ kubectl apply --filename blue-green-route.yaml
```

現在はまだ先に作ったgreenに100%のトラフィックが流れている状態です。

```
```shell
$ curl -H "Host: blue-green-demo.default.example.com" http://${IP_ADDRESS}
Hello blue!
```
Expand Down Expand Up @@ -380,9 +388,7 @@ Eventingの責務はイベントのバインディングとデリバリーです

つぎの図をイメージしながら進めてください。

***********
図を足す
***********
![](./images/eventing.png)

## Hello World

Expand Down Expand Up @@ -456,7 +462,7 @@ $ kubectl delete --filename cronjob-source.yaml

## PubSub

今度はCloud PubSubのイベントを処理してみましょう
今度は[Cloud Pub/Sub](https://cloud.google.com/pubsub/)のイベントを処理してみましょう

まずGCP Cloud Pub/Subをイベントソースとするためにつぎのコマンドを実行してください。

Expand All @@ -474,7 +480,6 @@ GCPのサービスアカウントを準備します。つぎのコマンドを

```shell
$ gcloud iam service-accounts create cloudrunevents-pullsub
Created service account [cloudrunevents-pullsub]
```

作成したサービスアカウントにPub/Sub Editorロールを付与してください。
Expand Down Expand Up @@ -534,6 +539,8 @@ spec:
```shell
$ kubectl apply -f pullsubscription.yaml
# 少し時間がかかるので注意
$ kubectl get pullsubscription -w
```

PubSubのトピックにイベントを発行してください。メッセージはなんでも大丈夫です。
Expand Down Expand Up @@ -648,7 +655,7 @@ build-kaniko-helloworld-gcr-pod-e686b3 0/4 Completed 0 78s
$ gcloud container images list-tags gcr.io/$PROJECT_ID/helloworld-go
```

`kubectl logs build-kaniko-helloworld-gcr-pod-e686b3`を実行するとPodで複数のコンテナが動いていることが確認できます。`-c`オプションでそれぞれのコンテナを指定するとコンテナのログも確認できます。
`kubectl logs build-kaniko-helloworld-gcr-pod-e686b3`(人によってe686b3の部分は異なります)を実行するとPodで複数のコンテナが動いていることが確認できます。`-c`オプションでそれぞれのコンテナを指定するとコンテナのログも確認できます。

確認ができたらいったん登録した`Task``TaskRun`を削除してください。

Expand Down
12 changes: 5 additions & 7 deletions step2.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

セットアップが済んだらKnariveで構築するFaaSプラットフォームの事例としてプラットフォーム利用者観点で見ていきましょう。

https://github.com/triggermesh/tm
https://github.com/triggermesh/knative-lambda-runtime/blob/master/go-1.x/runtime.yaml

KLRは`tm`というコマンドで操作します。つぎのコマンドを実行して`tm`をインストールしてください。

```shell
Expand All @@ -28,14 +25,15 @@ $ tm set registry-auth gcr-image-puller
# Password: <gcloud auth print-access-tokenを実行して得られる値>
```

いよいよfuncionをデプロイします。つぎのファイルを`main.go`という名前で保存し、`tm`コマンドを実行してデプロイしてください。
いよいよfuncionをデプロイします。つぎのファイルを`klr`というフォルダの下に`main.go`という名前で保存し、`tm`コマンドを実行してデプロイしてください。

```go
package main

import (
"fmt"
"context"

"github.com/aws/aws-lambda-go/lambda"
)

Expand All @@ -53,7 +51,7 @@ func main() {
```

```shell
$ tm deploy service go-lambda -f . --build-template knative-go-runtime --registry-secret gcr-image-puller --wait
$ tm deploy service go-lambda -f ./klr --build-template knative-go-runtime --registry-secret gcr-image-puller --wait
Uploading "." to go-lambda-q7dzp-pod-7881a3
Waiting for taskrun "go-lambda-q7dzp" ready state
Waiting for service "go-lambda" ready state
Expand All @@ -63,8 +61,8 @@ Service go-lambda URL: http://go-lambda.default.example.com
つぎのコマンドでfunctionが実行されるのを確認してください。

```shell
# export KNATIVE_INGRESS=$(kubectl get svc istio-ingressgateway --namespace istio-system --output 'jsonpath={.status.loadBalancer.ingress[0].ip}')
$ curl -H "Host: go-lambda.default.example.com" http://$KNATIVE_INGRESS --data '{"Name": "Foo"}'
# export IP_ADDRESS=$(kubectl get svc istio-ingressgateway --namespace istio-system --output 'jsonpath={.status.loadBalancer.ingress[0].ip}')
$ curl -H "Host: go-lambda.default.example.com" http://$IP_ADDRESS --data '{"Name": "Foo"}'
```

## 参考
Expand Down
2 changes: 1 addition & 1 deletion step3.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ $ tm deploy service go-function -f ./faas --build-template faas-go-runtime --reg
つぎのコマンドを実行して動作を確認してください。

```
$ curl -H "Host: go-function.default.example.com" http://$KNATIVE_INGRESS --data '{"Name": "Foo"}'
$ curl -H "Host: go-function.default.example.com" http://$IP_ADDRESS --data '{"Name": "Foo"}'
```
## 検討事項
Expand Down

0 comments on commit ea89c0a

Please sign in to comment.