概要
Knativeは、Kubernetes上でサーバーレスアプリを簡単にデプロイ&スケーリングできるフレームワークです。
この記事では、Mac mini (2023)上で、
KnativeでHello Worldした内容を共有させていただきます。
インストール方法
以下は、Knative CLI(kn
)をMacにインストールし、
KnativeとKubernetesをMinikubeのインスタンスにインストールするコマンドです。
brew install knative/client/kn
brew install knative-extensions/kn-plugins/quickstart
kn quickstart minikube
minikube環境にアクセスするためのトンネル設定:
minikube tunnel --profile knative
動作チェック:
$ minikube profile list
|---------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|---------|-----------|---------|--------------|------|---------|---------|-------|--------|
| knative | docker | docker | 192.168.49.2 | 8443 | v1.30.0 | Running | 1 | |
|---------|-----------|---------|--------------|------|---------|---------|-------|--------|
Hello Worldのデプロイ
以下は、knativeによって用意されているイメージ ghcr.io/knative/helloworld-go
をKnative Serviceとしてデプロイした結果です。
$ kn service create hello \
--image ghcr.io/knative/helloworld-go:latest \
--port 8080 \
--env TARGET=World
Warning: Kubernetes default value is insecure, Knative may default this to secure in a future release: spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation, spec.template.spec.containers[0].securityContext.capabilities, spec.template.spec.containers[0].securityContext.runAsNonRoot, spec.template.spec.containers[0].securityContext.seccompProfile
Creating service 'hello' in namespace 'default':
0.053s The Route is still working to reflect the latest desired specification.
0.069s Configuration "hello" is waiting for a Revision to become ready.
0.080s ...
8.247s ...
8.260s Ingress has not yet been reconciled.
8.292s Waiting for load balancer to be ready
8.488s Ready to serve.
Service 'hello' created to latest revision 'hello-00001' is available at URL:
http://hello.default.127.0.0.1.sslip.io
上記で標準出力をcurlで叩くとHello World文字列が返ってきます。
$ curl 'http://hello.default.127.0.0.1.sslip.io'
Hello World!
おわりに
今回は、Knativeを使用してMac mini (2023)上でHello Worldアプリケーションをデプロイし、その動作を確認しました。Knativeを使うことで、サーバーレスアプリケーションのデプロイが非常に簡単に行えることがわかりました。
今回の記事ではスケーリングの様子については触れていませんが、次回の記事でKnativeのスケーリング機能やその動作について取り上げたいと思います。