Home
Slides
Blog
slide.seike460.com
Home
Slides
Blog
Home
Slides
Fukuoka.php #29
Fukuoka.php #29
Fukuoka.php #29
2019年5月31日
PHP
PHP
Cloud Run
GCP
Keyboard Shortcuts
←
→
Navigate slides
Space
Next slide
F
Fullscreen
ESC
Exit fullscreen
Home
First slide
End
Last slide
B
.
Pause
S
Speaker notes
?
Reveal.js help
Close
## Knative PHP ## 平成最後の Fukuoka.php Vol.29 清家史郎(@seike460)
###### Who? Fusic Co., Ltd.  清家史郎  @seike460 [](https://twitter.com/seike460) [](https://www.facebook.com/seike460) [](https://github.com/seike460)
### tech - Program Language - PHP - Go - infrastructure - Server, Network - IaC - Cloud - AWS SA Professional - Other - Serverless - Vue.js、React
### OSS products - AWS Tools (Go) - [FictionBase](https://github.com/fictionbase/fictionbase) - Serverless Runtimel Base - [s3ry](https://github.com/seike460/s3ry) - S3 prompt cli - [utakata](https://github.com/seike460/utakata) - Serverless Slack iCal Notificator
このスライドは公開済みです https://slide.seike460.com/slides/fukuokaphp29#/
# 15秒告知
#### Serverless Meetup Fukuoka #5 - 6〜7月を予定 - 登壇者募集!!!
#### PHPカンファレンス福岡2019 `#phpconfuk` - 2019.6.29(sat) 10:00 - 18:00 
### Go Conference '19 Summer in Fukuoka - 2019.7.13(sat) 10:00 - 19:00 - スピーカー・スポンサー募集中!!!!
#### Agenda - Kubernetes、Knativeとは - Knative Hello World PHP - (おまけ)Google Cloud Run - まとめ
### Kubernetesとは ``` コンテナ化したアプリケーションのデプロイ、スケーリング、および管理を行うための、 オープンソースのコンテナオーケストレーションシステム ``` 3大クラウドベンダーにも管理環境が存在 - GCP - Google Kubernetes Engine(GKE) - AWS - Elastic Container Service for Kubernetes(EKS) - Azure - Azure Kubernetes Service(AKS)
### Kubernetesをもう少し詳しく - Master - Kubernetesクラスタ内のコンテナを管理するサーバー - kubectlコマンドからのリクエストを受けつけて処理を行う - Node - コンテナを動作させるサーバ - Podというコンテナ群をまとめた単位でコンテナを処理出来る
### Pod Kubernetesの最も小さい基本的な構成単位 - 共有ストレージを利用してデータの共有が可能 - Kubernetesが作成するClusterNetworで接続出来る - 設定したPod数を維持する様な設定を行う事が出来る - 5コンテナ動いていた -> 1コンテナ異常発生 - 5コンテナに戻す
### Kubernetes Architecture 
### Kubernetes Component
出典:[Concepts Underlying the Cloud Controller Manager](https://kubernetes.io/docs/concepts/architecture/cloud-controller/)
Componentの詳細を記述しようと思ったら最高のqiitaが [Kubernetes: 構成コンポーネント一覧](https://qiita.com/tkusumi/items/c2a92cd52bfdb9edd613)
### Knativeとは ``` Knative は、オンプレミス、クラウド、サードパーティのデータセンターなど、 場所を選ばず実行できるソース中心でコンテナベースの最新アプリケーションを 構築する際には不可欠な一連のミドルウェア コンポーネント サーバーレス ワークロードをビルド、デプロイ、管理できる Kubernetes ベースのプラットフォーム ``` コンテナ化したアプリケーションをサーバーレスに提供出来る つまりPHPをコンテナ化したら、サーバーレスPHP出来る
### Knative の 機能 - Serving - ゼロまでスケーリング、リクエスト ベースのコンピューティングモデル - Build - クラウド ネイティブなソースからコンテナに至るオーケストレーション - Events - イベントのユニバーサルなサブスクリプション、配信、管理
### Istio サービスメッシュを実現するソフトウェア ``` サービスメッシュとは 複雑化するマイクロサービスの課題解決を行うための仕組み 全てのサービスにサイドカープロキシを用意して サービス間のコミュニケーションをすべてサイドカープロキシ経由で行う ``` - Service Discovery - Fault Isolation - Observability - Security
### KnativeでHello World - PHP [Hello World - PHP](https://knative.dev/v0.4-docs/serving/samples/hello-world/helloworld-php/) - PHPコンテナを用意 - KubernetesでClusterを作成 - Knative用のyamlを作成
### PHPコンテナを用意 PHPファイル作成 ```
DockerFile作成 ``` # Use the official PHP 7.2 image. # https://hub.docker.com/_/php FROM php:7.2.6-apache # Copy local code to the container image. COPY index.php /var/www/html/ # Use the PORT environment variable in Apache configuration files. RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf ```
DockerHubにPush ``` # Build the container on your local machine docker build -t seike460/helloworld-php . # Push the container to docker registry docker push seike460/helloworld-php ```
### KubernetesでClusterを作成 GKE上にCluster作成 ``` seike460@cloudshell:~ (knative-php)$ gcloud container clusters create seike460 --zone=asia-northeast2 ```
Istio の設定 ``` seike460@cloudshell:~ (knative-php)$ kubectl apply -f https://github.com/knative/serving/releases/download/v0.5.0/istio-crds.yaml seike460@cloudshell:~ (knative-php)$ kubectl apply -f https://github.com/knative/serving/releases/download/v0.5.0/istio.yaml ```
default ネームスペースでIstio を有効化 ``` seike460@cloudshell:~ (knative-php)$ kubectl label namespace default istio-injection=enabled ```
Knativeのコンポーネントをインストール ``` seike460@cloudshell:~ (knative-php)$ kubectl apply -f https://github.com/knative/serving/releases/download/v0.5.0/serving.yaml seike460@cloudshell:~ (knative-php)$ kubectl apply -f https://github.com/knative/build/releases/download/v0.5.0/build.yaml seike460@cloudshell:~ (knative-php)$ kubectl apply -f https://github.com/knative/eventing/releases/download/v0.5.0/release.yaml seike460@cloudshell:~ (knative-php)$ kubectl apply -f https://github.com/knative/eventing-sources/releases/download/v0.5.0/eventing-sources.yaml seike460@cloudshell:~ (knative-php)$ kubectl apply -f https://github.com/knative/serving/releases/download/v0.5.0/monitoring.yaml seike460@cloudshell:~ (knative-php)$ kubectl apply -f https://raw.githubusercontent.com/knative/serving/v0.5.0/third_party/config/build/clusterrole.yaml ```
Servingする為のyaml設定作成 `service.yaml` ``` apiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: helloworld-php namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: docker.io/seike460/helloworld-php env: - name: TARGET value: "PHP Sample v1" ```
deploy ``` seike460@cloudshell:~ (knative-php)$ kubectl apply -f service.yaml ```
公開されているIPアドレスを取得 ``` seike460@cloudshell:~ (knative-php)$ kubectl get svc istio-ingressgateway --namespace istio-system ```
VirtualHostで待ち受けているのでサービスに紐付けられたDomainを取得 ``` seike460@cloudshell:~ (knative-php)$ kubectl get ksvc helloworld-php NAME DOMAIN LATESTCREATED LATESTREADY READY REASON helloworld-php helloworld-php.default.example.com helloworld-php-z8k6r helloworld-php-z8k6r True ```
``` kubectl get pods ``` ``` http://helloworld-php.default.example.com/ ``` ``` kubectl get pods ```
### (おまけ)Google Cloud Run #### GKEの料金 ``` GKE では、Google Compute Engine インスタンスをクラスタ内のノードとして使用します ノードを削除するまでは、Compute Engine の料金設定に基づいて、これらのインスタンスごとに課金されます ``` Google Compute Engine分の料金が発生
GCPUGにて Cloud Run API を教えてもらう [Cloud Run API](https://console.cloud.google.com/marketplace/details/google/run.googleapis.com)
#### JUST DO IT ``` seike460@cloudshell:~ (knative-php)$ gcloud beta run deploy --image gcr.io/knative-samples/helloworld-go Please specify a region: [1] us-central1 [2] cancel Please enter your numeric choice: 1 To make this the default region, run `gcloud config set run/region us-central1`. Service name: (helloworld-go): Deploying container to Cloud Run service [helloworld-go] in project [knative-php] region [us-central1] Allow unauthenticated invocations to new service [helloworld-go]? (y/N)? y ✓ Deploying new service... Done. ✓ Creating Revision... ✓ Routing traffic... ✓ Setting IAM Policy... Done. Service [helloworld-go] revision [helloworld-go-00001] has been deployed and is serving traffic at https://helloworld-go-cssowh6zpa-uc.a.run.app ``` ※DockerHubでは無くて GCRを利用しなければならない

#### まとめ - KnativeはKubernetes上で実行出来るServerless環境を提供 - Kubernetesはコンテナベースで実行が可能なのでPHPを利用できる - PHPでのServerless環境としてKnativeに未来がありそう
Thank you! Fusicは技術が大好きなエンジニアを募集しています  https://fusic.github.io
Swipe to navigate
Previous
Next
Related Slides
PHPで作るWebSocketサーバー
2024/6/1
View
PHPを書く理由、PHPを書いていて良い理由
2024/1/1
View
有効な使い方を正しく理解して実装する PHP8.3の最新機能の「ウラ側」
2023/11/1
View