LoginSignup
0

More than 3 years have passed since last update.

posted at

updated at

AKSでKnativeする

Knativeを使ってみたかった

なかなか手の出しにくいKnativeに挑戦。 AKS Knative で検索するとやっている人は少数のようですね。

AKSでやってみよう

  • Knative公式 にもAKSはありました。要件が厳しい。
    • Kubernetes version 1.14 or later
    • Three or more nodes
    • Standard_DS3_v2 nodes
    • RBAC enabled

 ひえ〜〜厳しい。無料枠でやりたいので Standard_DS3_v2 nodes を諦めて Standard_DS2_v2 にしました。
デフォルトには制限があるので、この要件で建てるのは難しそう。
https://docs.microsoft.com/ja-jp/azure/virtual-machines/windows/sizes-general

実際に建てようとすると怒られます。

Operation failed with status: 'Bad Request'. Details: Provisioning of resource(s) for container service knative-cluster in resource group knative-group failed. Message: The operation couldn't be completed as it results in exceeding quota limit of Core. Maximum allowed: 10, Current in use: 0, Additional requested: 12. Read more about quota limits at https://aka.ms/AzurePerVMQuotaLimits. Submit a request for Quota increase using the link https://aka.ms...

一応調べてみます。 https://docs.microsoft.com/ja-jp/azure/virtual-machines/windows/quotas

PS Azure:\> Get-AzVMUsage -Location "East US"

Name                              Current Value Limit  Unit
----                              ------------- -----  ----
略
Standard DSv3 Family vCPUs                    0    10 Count
略

Azure:/
PS Azure:\>

で、実際にこちらで建てました。 eastusでv1.15.4を使います。

$ az aks create --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --kubernetes-version 1.15.4  --node-vm-size Standard_DS2_v2 --ssh-key-value ~/.ssh/azure_id_rsa.pub --node-count 3

クラスタが起動したらistioはこちらを参考
https://docs.microsoft.com/ja-jp/azure/aks/servicemesh-istio-install?pivots=client-operating-system-macos

Knative公式はhelmで書かれているが、MS公式はistioctl推奨、versionも1.4.0で書かれている。
Istioを入れたらKnativeはそのまま公式通りインストールします。
ここ に戻る。
ここまででpodの数が...

$ kubectl get po --all-namespaces
NAMESPACE            NAME                                      READY   STATUS              RESTARTS   AGE
istio-system         grafana-6bc97ff99-kxtlr                   1/1     Running             0          8m37s
istio-system         istio-citadel-6b5c754454-dllvm            1/1     Running             0          8m44s
istio-system         istio-galley-7d6d78d7c5-kgjxk             2/2     Running             0          8m42s
istio-system         istio-ingressgateway-85869c5cc7-wshw9     1/1     Running             0          8m44s
istio-system         istio-pilot-787d6995b5-mglxg              2/2     Running             0          8m42s
istio-system         istio-policy-6cf4fbc8dc-5m52m             2/2     Running             1          8m43s
istio-system         istio-sidecar-injector-5d5b978668-gvvwk   1/1     Running             0          8m41s
istio-system         istio-telemetry-5498db684-kg9h2           2/2     Running             1          8m42s
istio-system         istio-tracing-78548677bc-d989w            1/1     Running             0          8m45s
istio-system         kiali-59b7fd7f68-mgkkb                    1/1     Running             0          8m42s
istio-system         prometheus-7c7cf9dbd6-xjthf               1/1     Running             0          8m42s
istio-system         zipkin-65889cbb48-rlcmf                   0/1     Pending             0          4s
knative-eventing     eventing-controller-66f887d744-v5tkl      1/1     Running             0          48s
knative-eventing     eventing-webhook-5c45f99585-8c8nn         1/1     Running             0          45s
knative-eventing     imc-controller-57cbf9bbd8-cpxt5           1/1     Running             0          39s
knative-eventing     imc-dispatcher-77c88d7dc4-7hfm7           1/1     Running             0          38s
knative-eventing     sources-controller-7df864ccf-65mmv        1/1     Running             0          47s
knative-monitoring   elasticsearch-logging-0                   0/1     PodInitializing     0          34s
knative-monitoring   grafana-68748c5b45-xjg4j                  0/1     ContainerCreating   0          13s
knative-monitoring   kibana-logging-b5d75f556-7x4zg            0/1     ContainerCreating   0          33s
knative-monitoring   kube-state-metrics-5cb5c6986b-5tmdz       0/1     ContainerCreating   0          27s
knative-monitoring   node-exporter-jslbh                       0/2     ContainerCreating   0          19s
knative-monitoring   node-exporter-ndgdz                       0/2     ContainerCreating   0          19s
knative-monitoring   node-exporter-sprvm                       2/2     Running             0          19s
knative-monitoring   prometheus-system-0                       0/1     ContainerCreating   0          5s
knative-monitoring   prometheus-system-1                       0/1     ContainerCreating   0          5s
knative-serving      activator-79f674fb7b-xwg7m                2/2     Running             0          77s
knative-serving      autoscaler-96dc49858-fndpp                2/2     Running             1          75s
knative-serving      autoscaler-hpa-d887d4895-t4cmh            1/1     Running             0          76s
knative-serving      controller-6bcdd87fd6-szsqv               1/1     Running             0          70s
knative-serving      networking-istio-7fcd97cbf7-5mtcq         1/1     Running             0          66s
knative-serving      webhook-747b799559-vttcp                  1/1     Running             0          69s
kube-system          coredns-68c85fc5d4-mvms4                  1/1     Running             0          22m
kube-system          coredns-68c85fc5d4-sfb4x                  1/1     Running             0          18m
kube-system          coredns-autoscaler-875fb445c-xkrpq        1/1     Running             0          22m
kube-system          kube-proxy-4gqsm                          1/1     Running             0          18m
kube-system          kube-proxy-c8hh2                          1/1     Running             0          19m
kube-system          kube-proxy-n7v9t                          1/1     Running             0          18m
kube-system          kubernetes-dashboard-5758d48c87-c89rn     1/1     Running             0          22m
kube-system          metrics-server-957757c9f-fgcbp            1/1     Running             0          22m
kube-system          tunnelfront-c576f5878-jf94z               1/1     Running             0          22m

さてこれで必要なものが揃ったので、HelloWorldしてみます。
https://knative.dev/docs/eventing/samples/helloworld/helloworld-go/###Send-CloudEvent-to-the-Broker

https://github.com/knative/docsdocs/eventing/samples/helloworld を使ってみます。
CloudEvent を使った簡単なアプリをデプロイします。

上記docsリポジトリのhelloworld に DockerfileがあるのでそれをbuildしてDockerhubにPushします。
作ったImageを指定した状態でsample-appをdeployします。

knative-samples      default-broker-filter-5f899d7684-9j8dk    1/1     Running   0          33m
knative-samples      default-broker-ingress-7fff74f7d8-nlbl9   1/1     Running   0          33m
knative-samples      helloworld-go-7c58bcc5f-lx596             1/1     Running   0          33m

curlでPOSTした結果がこちら

[ root@curl-6bf6db5c4f-tgtf8:/ ]$   curl -v "default-broker.knative-samples.svc.cluster.local" \
>   -X POST \
>   -H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
>   -H "Ce-specversion: 0.3" \
>   -H "Ce-Type: dev.knative.samples.helloworld" \
>   -H "Ce-Source: dev.knative.samples/helloworldsource" \
>   -H "Content-Type: application/json" \
>   -d '{"msg":"Hello World from the curl pod."}'
> POST / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: default-broker.knative-samples.svc.cluster.local
> Accept: */*
> Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79
> Ce-specversion: 0.3
> Ce-Type: dev.knative.samples.helloworld
> Ce-Source: dev.knative.samples/helloworldsource
> Content-Type: application/json
> Content-Length: 40
> 
< HTTP/1.1 202 Accepted
< Content-Length: 0
< Date: Thu, 12 Dec 2019 16:26:24 GMT
< 
[ root@curl-6bf6db5c4f-tgtf8:/ ]$ exit

アプリ側のログの確認

$ kubectl --namespace knative-samples logs -l app=helloworld-go --tail=50 
2019/12/12 16:24:04 Hello world sample started.
2019/12/12 16:26:24 Event received. Context: Context Attributes,
  specversion: 0.3
  type: dev.knative.samples.helloworld
  source: dev.knative.samples/helloworldsource
  id: 536808d3-88be-4077-9d7a-a3f162705f79
  time: 2019-12-12T16:26:24.887351953Z
  datacontenttype: application/json
Extensions,
  knativearrivaltime: 2019-12-12T16:26:24Z
  knativehistory: default-kne-trigger-kn-channel.knative-samples.svc.cluster.local
  traceparent: 00-30a9dddc4c694ca766cc4c2916011920-5193c1279cc6a8a5-00

2019/12/12 16:26:24 Hello World Message from received event "Hello World from the curl pod."
2019/12/12 16:26:24 Responded with event Validation: valid
Context Attributes,
  specversion: 0.2
  type: dev.knative.samples.hifromknative
  source: knative/eventing/samples/hello-world
  id: 0ef10b40-9672-4e5f-863e-aa04dd82b3fb
Data,
  {"msg":"Hi from helloworld-go app!"}

"Hello World from the curl pod." で curlのDataが渡っていることを確認。
{"msg":"Hi from helloworld-go app!"} でDataを返しているのも確認。

なるほど〜〜〜!

所感

  • サーバレスってところをあまり意識しなくて済むけどもその上のpodの数が多いので管理が大変。。
    結局最終的には45程度のpodがdeployされている状態(Productionを考えると倍くらいになりそう)ということを考えると、大きめのクラスタが必要で、かつ監視もしっかりやる必要がありそう。(Ops側が大変そう)

  • Sample を見ると他にも色々なイベント発火でアプリを動かせそう。(GoogleのCloudとの親和性が高い)

  • 一通りやってみて、ツラミが多かったが、 CloudEvent は面白そうに感じた。最近version1.0がリリースされたみたいなので今度はこちらを触ってみたいと思います!

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0