IK.AM

@making's tech note


Tanzu Application Platform 0.3 (Beta-3) をKindにインストールし"Source to URL"を試すメモ

🗃 {Dev/CaaS/Kubernetes/TAP}
🏷 Kubernetes 🏷 Cartographer 🏷 kind 🏷 Tanzu 🏷 TAP 🏷 Knative 
🗓 Updated at 2021-11-21T12:09:23Z  🗓 Created at 2021-11-21T11:57:42Z   🌎 English Page

⚠️ 本記事の内容はVMwareによってサポートされていません。 記事の内容で生じた問題については自己責任で対応し、 VMwareサポート窓口には問い合わせないでください

Tanzu Application Platform v0.3 (Beta-3) をKindにインストールします。TKGにインストールしたい場合はこちらを参照してください。

TAPはKubernetes上でCloud FoundryやHerokuのようなDeveloper Experienceを提供するPlatformです。

本記事ではTAPをInstallし、"Hello World"なアプリケーションをソースコードからデプロイする機能("Source to URL")を試します。

目次

Kindクラスタの作成

cat <<EOF > kind-expose-port.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
 - role: control-plane
 - role: worker
   extraPortMappings:
   - containerPort: 31443 # expose port 31443 of the node to port 80 on the host for use later by Contour ingress (envoy)
     hostPort: 443
   - containerPort: 31080 # expose port 31080 of the node to port 80 on the host for use later by Contour ingress (envoy)
     hostPort: 80
EOF
kind create cluster --config kind-expose-port.yaml

プラグインのインストール

tanzu CLIはTAPからも配布されていますが、TKG用のものを使用します。TAP用のものを使用しても良いです。

$ tanzu version
version: v1.4.0
buildDate: 2021-08-30
sha: c9929b8f

こちらのドキュメント にしたがって、既存の tanzu CLIにプラグインを追加します。

プラグインは こちら からダウンロードできますが、ここでは pivnet CLIを使用してダウンロードします。 pivnet CLIはbrewでインストールできます。

brew install pivotal/tap/pivnet-cli

VMware Tanzu Network のAPI Tokenを取得して、pivnet CLIでログインします。

pivnet login --api-token=<API Token>

プラグインをダウンロードします

# Macの場合
pivnet download-product-files --product-slug='tanzu-application-platform' --release-version='0.3.0' --product-file-id=1080177

# Linuxの場合
pivnet download-product-files --product-slug='tanzu-application-platform' --release-version='0.3.0' --product-file-id=1080178

# Windowsの場合
pivnet download-product-files --product-slug='tanzu-application-platform' --release-version='0.3.0' --product-file-id=1080168

Macの場合の手順をメモします。

mkdir $HOME/tanzu
tar -xvf tanzu-framework-darwin-amd64.tar -C $HOME/tanzu
cd $HOME/tanzu

# 古いプラグインがあれば削除
tanzu plugin delete imagepullsecret
tanzu plugin delete package

# TAP用のプラグインを追加
tanzu plugin install secret --local ./cli
tanzu plugin install accelerator --local ./cli
tanzu plugin install apps --local ./cli
tanzu plugin install package --local ./cli

プラグイン一覧が次のようになればOKです。

$ tanzu plugin list
  NAME                LATEST VERSION  DESCRIPTION                                                        REPOSITORY  VERSION  STATUS             
  accelerator                         Manage accelerators in a Kubernetes cluster                                    v0.4.1   installed          
  alpha               v1.4.0          Alpha CLI commands                                                 core                 not installed      
  apps                                Applications on Kubernetes                                                     v0.2.0   installed          
  cluster             v1.4.0          Kubernetes cluster operations                                      core        v1.4.0   installed          
  kubernetes-release  v1.4.0          Kubernetes release operations                                      core        v1.4.0   installed          
  login               v1.4.0          Login to the platform                                              core        v1.4.0   installed          
  management-cluster  v1.4.0          Kubernetes management cluster operations                           core        v1.4.0   installed          
  package             v1.4.0          Tanzu package management                                           core        v0.10.0  upgrade available  
  pinniped-auth       v1.4.0          Pinniped authentication operations (usually not directly invoked)  core        v1.4.0   installed          
  secret                              Tanzu secret management                                                        v0.10.0  installed  

事前準備

TAPをインストールする前にインストールが必要なコンポーネントをインストールします。

kapp-controllerのインストール

TAPは kapp-controller を使って宣言的にインストールされます。

kapp deploy -y -a kc -f https://github.com/vmware-tanzu/carvel-kapp-controller/releases/download/v0.29.0/release.yml

# または

kubectl apply -f https://github.com/vmware-tanzu/carvel-kapp-controller/releases/download/v0.29.0/release.yml

secretgen-controllerのインストール

TAPのインストール時にSecretを他のnamespaceにexportするために secretgen-controller が使用されます。

kapp deploy -y -a sg -f https://github.com/vmware-tanzu/carvel-secretgen-controller/releases/download/v0.6.0/release.yml

# または

kubectl create ns secretgen-controller
kubectl apply -f  https://github.com/vmware-tanzu/carvel-secretgen-controller/releases/download/v0.6.0/release.yml

EULAの承諾

初回はTAPで使用するコンポーネントのEULA (End User License Agreement)を承諾する必要があります。 Webブラウザから承諾しても良いですが、楽をしたい場合は次のコマンドでもまとめて承諾できます。 必要十分な量かわかりません。多分余分なので少し時間がかかります。

for p in $(pivnet products | grep 'tanzu-.*-buildpack' | awk '{print $4}');do
  echo $p
  pivnet curl -X POST $(pivnet releases -p ${p} --format=json | jq -r '.[0]._links.eula_acceptance.href')
  echo
done
for p in $(pivnet products | grep 'tanzu-.*-stack' | awk '{print $4}');do
  echo $p
  pivnet curl -X POST $(pivnet releases -p ${p} --format=json | jq -r '.[0]._links.eula_acceptance.href')
  echo
done
for p in build-service tbs-dependencies tanzu-application-platform api-portal;do
  echo $p
  pivnet curl -X POST $(pivnet releases -p ${p} --format=json | jq -r '.[0]._links.eula_acceptance.href')
  echo
done

TAPのインストール

TAPは Carvel Package としてOCIイメージで配布されています。 このOCIレジストリにアクセスするためのSecretを tap-install namespaceに作成します。

TANZUNET_USERNAME=...
TANZUNET_PASSWORD=...

kubectl create ns tap-install
tanzu secret registry add tap-registry \
  --username "$TANZUNET_USERNAME" --password "$TANZUNET_PASSWORD" \
  --server registry.tanzu.vmware.com \
  --export-to-all-namespaces --yes --namespace tap-install

TAPのpackage repositoryを登録します。

tanzu package repository add tanzu-tap-repository \
  --url registry.tanzu.vmware.com/tanzu-application-platform/tap-packages:0.3.0 \
  --namespace tap-install

利用可能なパッケージが次のように出力されればOKです。

$ tanzu package available list --namespace tap-install
| Retrieving available packages... 
  NAME                                                 DISPLAY-NAME                                                              SHORT-DESCRIPTION                                                                                                                                              LATEST-VERSION  
  accelerator.apps.tanzu.vmware.com                    Application Accelerator for VMware Tanzu                                  Used to create new projects and configurations.                                                                                                                0.4.0           
  api-portal.tanzu.vmware.com                          API portal                                                                A unified user interface to enable search, discovery and try-out of API endpoints at ease.                                                                     1.0.3           
  appliveview.tanzu.vmware.com                         Application Live View for VMware Tanzu                                    App for monitoring and troubleshooting running apps                                                                                                            0.3.0           
  buildservice.tanzu.vmware.com                        Tanzu Build Service                                                       Tanzu Build Service enables the building and automation of containerized software workflows securely and at scale.                                             1.3.1           
  cartographer.tanzu.vmware.com                        Cartographer                                                              Kubernetes native Supply Chain Choreographer.                                                                                                                  0.0.7           
  cnrs.tanzu.vmware.com                                Cloud Native Runtimes                                                     Cloud Native Runtimes is a serverless runtime based on Knative                                                                                                 1.0.3           
  controller.conventions.apps.tanzu.vmware.com         Convention Service for VMware Tanzu                                       Convention Service enables app operators to consistently apply desired runtime configurations to fleets of workloads.                                          0.4.2           
  controller.source.apps.tanzu.vmware.com              Tanzu Source Controller                                                   Tanzu Source Controller enables workload create/update from source code.                                                                                       0.1.2           
  developer-conventions.tanzu.vmware.com               Tanzu App Platform Developer Conventions                                  Developer Conventions                                                                                                                                          0.3.0           
  grype.scanning.apps.tanzu.vmware.com                 Grype Scanner for Supply Chain Security Tools for VMware Tanzu - Scan     Default scan templates using Anchore Grype                                                                                                                     1.0.0-beta.2    
  image-policy-webhook.signing.run.tanzu.vmware.com    Image Policy Webhook                                                      The Image Policy Webhook allows platform operators to define a policy that will use cosign to verify signatures of container images                            1.0.0-beta.1    
  learningcenter.tanzu.vmware.com                      Learning Center for Tanzu Application Platform                            Guided technical workshops                                                                                                                                     1.0.14-build.1  
  ootb-supply-chain-basic.tanzu.vmware.com             Tanzu App Platform Out of The Box Supply Chain Basic                      Out of The Box Supply Chain Basic.                                                                                                                             0.3.0-build.5   
  ootb-supply-chain-testing-scanning.tanzu.vmware.com  Tanzu App Platform Out of The Box Supply Chain with Testing and Scanning  Out of The Box Supply Chain with Testing and Scanning.                                                                                                         0.3.0-build.5   
  ootb-supply-chain-testing.tanzu.vmware.com           Tanzu App Platform Out of The Box Supply Chain with Testing               Out of The Box Supply Chain with Testing.                                                                                                                      0.3.0-build.5   
  ootb-templates.tanzu.vmware.com                      Tanzu App Platform Out of The Box Templates                               Out of The Box Templates.                                                                                                                                      0.3.0-build.5   
  scanning.apps.tanzu.vmware.com                       Supply Chain Security Tools for VMware Tanzu - Scan                       Scan for vulnerabilities and enforce policies directly within Kubernetes native Supply Chains.                                                                 1.0.0-beta.2    
  scst-store.tanzu.vmware.com                          Tanzu Supply Chain Security Tools - Store                                 The Metadata Store enables saving and querying image, package, and vulnerability data.                                                                         1.0.0-beta.1    
  service-bindings.labs.vmware.com                     Service Bindings for Kubernetes                                           Service Bindings for Kubernetes implements the Service Binding Specification.                                                                                  0.5.0           
  services-toolkit.tanzu.vmware.com                    Services Toolkit                                                          The Services Toolkit enables the management, lifecycle, discoverability and connectivity of Service Resources (databases, message queues, DNS records, etc.).  0.4.0           
  spring-boot-conventions.tanzu.vmware.com             Tanzu Spring Boot Conventions Server                                      Default Spring Boot convention server.                                                                                                                         0.1.2           
  tap-gui.tanzu.vmware.com                             Tanzu Application Platform GUI                                            web app graphical user interface for Tanzu Application Platform                                                                                                0.3.0           
  tap.tanzu.vmware.com                                 Tanzu Application Platform                                                Package to install a set of TAP components to get you started based on your use case.                                                                          0.3.0           
  workshops.learningcenter.tanzu.vmware.com            Workshop Building Tutorial                                                Workshop Building Tutorial                                                                                                                                     1.0.7-build.1 

Packageの仕組みは Tanzu Community Edition のドキュメントが詳しいです

TAPは複数のコンポーネントから構成されており、必要に応じて取捨選択できます。ただし個別で全てのコンポーネントをインストールするのは面倒くさいので、 よく使うものをパッケージングした Profile が用意されています。0.3ではFull (full)とDeveloper Light (dev-light)の二つのProfileが用意されています。

今回はDeveloper Light Profileを使用します。このProfileをインストールするのに次の tap-values.yaml に設定を記述します。 ここではTAPではソースコードをコンテナイメージに変換する際にTBS (Tanzu Build Service)を使用しますが、ここではTBSがpushするコンテナレジストリにghcr.ioを利用します。

GITHUB_USERNAME=...
GITHUB_API_TOKEN=...

cat <<EOF > tap-values.yaml
profile: dev-light

cnrs:
  provider: local

buildservice:
  kp_default_repository: ghcr.io/${GITHUB_USERNAME}/build-service
  kp_default_repository_username: ${GITHUB_USERNAME}
  kp_default_repository_password: ${GITHUB_API_TOKEN}
  tanzunet_username: ${TANZUNET_USERNAME}
  tanzunet_password: ${TANZUNET_PASSWORD}

supply_chain: basic

ootb_supply_chain_basic:
  registry:
    server: ghcr.io
    repository: ${GITHUB_USERNAME}

learningcenter:
  ingressDomain: vcap.me

tap_gui:
  service_type: ClusterIP
EOF

設定可能な値は次のコマンドで確認できます。

tanzu package available get tap.tanzu.vmware.com/0.3.0 --values-schema --namespace tap-install

なお、Profileは"packageをインストールしたpackage"です。tap.tanzu.vmware.com/0.3.0 の設定一覧には個別のpackageの設定項目は出力されないため、 例えば、tap-values.yamlootb_supply_chain_basic prefixな設定項目を確認したい場合は、次のように ootb-supply-chain-basic.tanzu.vmware.com/0.3.0-build.5 の設定項目を見れば良いです。

$ tanzu package available get ootb-supply-chain-basic.tanzu.vmware.com/0.3.0-build.5 --values-schema --namespace tap-install
| Retrieving package details for ootb-supply-chain-basic.tanzu.vmware.com/0.3.0-build.5...
KEY                  DEFAULT          TYPE    DESCRIPTION                                                                                                                                                                                                  
cluster_builder      default          string  Name of the Tanzu Build Service (TBS) ClusterBuilder to use by default on image objects managed by the supply chain.                                                                                         
registry.repository  <nil>            string  Name of the repository in the image registry server where the application images from the workloads should be pushed to (required).                                                                          
registry.server      index.docker.io  string  Name of the registry server where application images should be pushed to (required).                                                                                                                         
service_account      default          string  Name of the service account in the namespace where the Workload is submitted to utilize for providing registry credentials to Tanzu Build Service (TBS) Image objects as well as deploying the application.

次のコマンドでインストールします。

tanzu package install tap -p tap.tanzu.vmware.com -v 0.3.0 --values-file tap-values.yaml -n tap-install

Packageによってkapp-controllerのApp CRがコンポーネントごとできます。各コンポーネントのインストールの進捗は次のコマンドでの DESCRIPTION で確認できます。 Reconciling になっているものはインストール中です。 Reconcile succeeded になればインストール成功です。

$ kubectl get app -n tap-install
NAME                     DESCRIPTION           SINCE-DEPLOY   AGE
buildservice             Reconciling           79s            92s
cartographer             Reconciling           74s            91s
cnrs                     Reconciling           74s            92s
conventions-controller   Reconciling           80s            92s
image-policy-webhook     Reconcile succeeded   79s            92s
service-bindings         Reconciling           74s            90s
services-toolkit         Reconciling           75s            90s
source-controller        Reconciling           76s            89s
tap                      Reconciling           2m11s          2m22s
tap-gui                  Reconciling           75s            91s

各コンポーネントのインストールの詳細は次のコマンドで確認できます。

kubectl get app -n tap-install <APP NAME> -oyaml

次のコマンドのインストール済みパッケージ一覧としても確認できます。

$ tanzu package installed list --namespace tap-install
\ Retrieving installed packages... 
  NAME                     PACKAGE-NAME                                       PACKAGE-VERSION  STATUS               
  appliveview              appliveview.tanzu.vmware.com                       0.3.0            Reconcile succeeded  
  buildservice             buildservice.tanzu.vmware.com                      1.3.1            Reconcile succeeded  
  cartographer             cartographer.tanzu.vmware.com                      0.0.7            Reconcile succeeded  
  cnrs                     cnrs.tanzu.vmware.com                              1.0.3            Reconcile succeeded  
  conventions-controller   controller.conventions.apps.tanzu.vmware.com       0.4.2            Reconcile succeeded  
  developer-conventions    developer-conventions.tanzu.vmware.com             0.3.0            Reconcile succeeded  
  image-policy-webhook     image-policy-webhook.signing.run.tanzu.vmware.com  1.0.0-beta.1     Reconcile succeeded  
  ootb-supply-chain-basic  ootb-supply-chain-basic.tanzu.vmware.com           0.3.0-build.5    Reconcile succeeded  
  ootb-templates           ootb-templates.tanzu.vmware.com                    0.3.0-build.5    Reconcile succeeded  
  service-bindings         service-bindings.labs.vmware.com                   0.5.0            Reconcile succeeded  
  services-toolkit         services-toolkit.tanzu.vmware.com                  0.4.0            Reconcile succeeded  
  source-controller        controller.source.apps.tanzu.vmware.com            0.1.2            Reconcile succeeded  
  spring-boot-conventions  spring-boot-conventions.tanzu.vmware.com           0.1.2            Reconcile succeeded  
  tap                      tap.tanzu.vmware.com                               0.3.0            Reconcile succeeded  
  tap-gui                  tap-gui.tanzu.vmware.com                           0.3.0            Reconcile succeeded  

Developer Light Profileインストール後のPod一覧は次のようになります。

$ kubectl get pod -A
NAMESPACE                NAME                                                    READY   STATUS    RESTARTS   AGE
app-live-view            application-live-view-crd-controller-55b4bf9469-tts7k   1/1     Running   0          14m
app-live-view            application-live-view-server-68f57b9d88-kkdh7           1/1     Running   0          14m
app-live-view            appliveview-webhook-8585544948-62kfv                    1/1     Running   0          14m
build-service            build-pod-image-fetcher-cbvhn                           5/5     Running   0          15m
build-service            cert-injection-webhook-7898956bd-2fvg9                  1/1     Running   0          15m
build-service            dependency-updater-controller-964957fdb-km2rv           1/1     Running   0          15m
build-service            secret-syncer-controller-6f6575f4d-rgk9f                1/1     Running   0          15m
build-service            warmer-controller-775bb9875d-wxvf9                      1/1     Running   0          15m
cartographer-system      cartographer-controller-dd9c9449d-4rv25                 1/1     Running   0          15m
cert-manager             cert-manager-7cdff7dfd9-4vj49                           1/1     Running   0          17m
cert-manager             cert-manager-cainjector-58f4f5ccb6-6sbgp                1/1     Running   0          17m
cert-manager             cert-manager-webhook-69856bf7fb-5hxjx                   1/1     Running   0          17m
contour-external         contour-7cc79cb586-4qp88                                1/1     Running   0          15m
contour-external         contour-7cc79cb586-7ksxm                                1/1     Running   0          15m
contour-external         envoy-qq524                                             2/2     Running   0          15m
contour-internal         contour-865498b5c8-q56m9                                1/1     Running   0          15m
contour-internal         contour-865498b5c8-zzkhf                                1/1     Running   0          15m
contour-internal         envoy-5tlwb                                             2/2     Running   0          15m
conventions-system       conventions-controller-manager-7649c457dd-d2qdq         1/1     Running   0          15m
default                  application-live-view-connector-6c7dbdf564-7qpm2        1/1     Running   0          14m
developer-conventions    webhook-bf76f477-5htjn                                  1/1     Running   0          14m
flux-system              source-controller-85fccf5477-wj4vp                      1/1     Running   0          17m
image-policy-system      image-policy-controller-manager-c786658d4-lwnjf         2/2     Running   0          16m
kapp-controller          kapp-controller-b8988c788-wl4wd                         1/1     Running   0          22m
knative-discovery        controller-86b589f855-zlk87                             1/1     Running   0          15m
knative-discovery        webhook-67cb69f568-bhlwj                                1/1     Running   0          15m
knative-eventing         eventing-controller-698f4fbc9f-hvghw                    1/1     Running   0          15m
knative-eventing         eventing-webhook-5bc7dcdd9f-27nx2                       1/1     Running   0          15m
knative-eventing         imc-controller-67f64cff9c-6wcb5                         1/1     Running   0          15m
knative-eventing         imc-dispatcher-54d4d4df6-cqqph                          1/1     Running   0          15m
knative-eventing         mt-broker-controller-7d8bbb8d6b-4nhkz                   1/1     Running   0          15m
knative-eventing         mt-broker-filter-6ccc9c8778-w98tn                       1/1     Running   0          15m
knative-eventing         mt-broker-ingress-78d66cb97b-lztmh                      1/1     Running   0          15m
knative-eventing         rabbitmq-broker-controller-9456cb646-pvd4n              1/1     Running   0          15m
knative-serving          activator-78698cfb67-qj6l9                              1/1     Running   0          15m
knative-serving          autoscaler-7799bd7897-8wg9c                             1/1     Running   0          15m
knative-serving          contour-ingress-controller-6fccc8b65b-r4zbp             1/1     Running   0          15m
knative-serving          controller-5f65565b5b-9rjfz                             1/1     Running   0          15m
knative-serving          net-certmanager-webhook-56586fdc68-xr9vm                1/1     Running   0          15m
knative-serving          networking-certmanager-588fb64fc-df8h4                  1/1     Running   0          15m
knative-serving          webhook-8699587744-q52jg                                1/1     Running   0          15m
knative-sources          rabbitmq-controller-manager-6cc9596996-dwh65            1/1     Running   0          15m
knative-sources          rabbitmq-webhook-654d5f4d68-c6zlw                       1/1     Running   0          15m
kpack                    kpack-controller-689ffd8c54-m9w7h                       1/1     Running   0          15m
kpack                    kpack-webhook-687b49bddd-nk49k                          1/1     Running   0          15m
kube-system              coredns-558bd4d5db-2jcq7                                1/1     Running   0          24m
kube-system              coredns-558bd4d5db-glhbq                                1/1     Running   0          24m
kube-system              etcd-kind-control-plane                                 1/1     Running   0          24m
kube-system              kindnet-c9bcd                                           1/1     Running   0          24m
kube-system              kube-apiserver-kind-control-plane                       1/1     Running   0          24m
kube-system              kube-controller-manager-kind-control-plane              1/1     Running   0          25m
kube-system              kube-proxy-t4c69                                        1/1     Running   0          24m
kube-system              kube-scheduler-kind-control-plane                       1/1     Running   0          24m
local-path-storage       local-path-provisioner-547f784dff-mfxzm                 1/1     Running   0          24m
scp-toolkit              scp-toolkit-controller-manager-6f5f5bf59f-v78tl         1/1     Running   0          15m
secretgen-controller     secretgen-controller-9c4cd6699-n8vvt                    1/1     Running   0          22m
service-bindings         manager-554fd6ff6-hn5gj                                 1/1     Running   0          15m
source-system            source-controller-manager-7c9c9f684b-868b5              1/1     Running   0          16m
spring-boot-convention   spring-boot-webhook-7697b7f7c6-bmfm8                    1/1     Running   0          14m
stacks-operator-system   controller-manager-76679754b4-5qch2                     1/1     Running   0          15m
tap-gui                  server-58975f6665-xtbvw                                 1/1     Running   0          16m
triggermesh              aws-event-sources-controller-7dfdc7b5-rbdzj             1/1     Running   0          15m
vmware-sources           webhook-6f8d6759cf-dlt69                                1/1     Running   0          15m

アプリケーションのデプロイ

TAP上にアプリケーションをデプロイしましょう。

事前準備

Service Accountへの設定

こちらのドキュメント の通り、アプリケーションをデプロイするnamespaceの作成、imagePullSecretの設定、及びRBACの設定が必要です。

今回はdemo namespaceを使用します。

kubectl create namespace demo

Tanzu Build Serviceが作成したイメージをpullするためのSecretを demo namespaceに作成します。

tanzu secret registry add registry-credentials --server ghcr.io --username ${GITHUB_USERNAME} --password ${GITHUB_API_TOKEN} --namespace demo

default Service Accountに対して、imagePullSecretの設定とRoleBindingの設定を行います。なお、このService Account名は tap-values.yaml で変更可能です。

cat <<EOF | kubectl -n demo apply -f -
apiVersion: v1
kind: Secret
metadata:
  name: tap-registry
  annotations:
    secretgen.carvel.dev/image-pull-secret: ""
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson: e30K
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: default
secrets:
- name: registry-credentials
imagePullSecrets:
- name: registry-credentials
- name: tap-registry
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: kapp-permissions
  annotations:
    kapp.k14s.io/change-group: "role"
rules:
- apiGroups:
  - servicebinding.io
  resources: [ 'servicebindings' ]
  verbs: [ '*' ]
- apiGroups:
  - services.tanzu.vmware.com
  resources: [ 'resourceclaims' ]
  verbs: [ '*' ]
- apiGroups:
  - serving.knative.dev
  resources: [ 'services' ]
  verbs: [ '*' ]
- apiGroups: [ "" ]
  resources: [ 'configmaps' ]
  verbs: [ 'get', 'watch', 'list', 'create', 'update', 'patch', 'delete' ]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: kapp-permissions
  annotations:
    kapp.k14s.io/change-rule: "upsert after upserting role"
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: kapp-permissions
subjects:
- kind: ServiceAccount
  name: default
EOF
ドメイン名の登録及

TAPへのHTTPリクエストはKnativeのIngress(ContourのEnvoy)が受け付けます。 Knativeがドメインとしてvcap.meを使用するように次の設定を行います。

*.vcap.me127.0.0.1に解決されます。

kubectl patch configmap config-domain -n knative-serving --type merge --patch '{"data":{"vcap.me":""}}'

Workloadの作成

いよいよアプリケーションをデプロイします。アプリケーションは Cartographer のWorkload CRにより作成されます。

TAPでgitレポジトリのソースコードからアプリケーションをデプロイする方法と、ローカルファイルからアプリケーションをデプロイする方法の2パターン選べます。

ソースコードはNode.jsのHello Worldアプリ (https://github.com/making/hello-nodejs) を使用します。

gitレポジトリからデプロイ

次のコマンドでデプロイできます。

tanzu apps workload create hello \
  --git-repo https://github.com/making/hello-nodejs \
  --git-branch master \
  --type web \
  -n demo -y

次のコマンドでログを追跡できます。

tanzu apps workload tail hello -n demo 

次のコマンドでアプリの情報を取得できます。

$ tanzu apps workload get hello -n demo
# hello: Ready
---
lastTransitionTime: "2021-11-15T10:49:44Z"
message: ""
reason: Ready
status: "True"
type: Ready

Workload pods
NAME                                    STATE       AGE
hello-00001-deployment-d5dc7569-4hfnq   Running     17s
hello-build-1-build-pod                 Succeeded   49s

Workload Knative Services
NAME    READY   URL
hello   Ready   http://hello.demo.vcap.me

出力されたURLにアクセスします。

$ curl http://hello.demo.vcap.me
Hello Tanzu!

以下はデモの録画です(URLは異なりますが、内容は同じです)。

tanzu-push-1

アプリケーションを更新したい場合は、変更したソースコードをgitにpushすれば自動でアプリが再デプロイされます。

ローカルファイルからデプロイ

次のコマンドでデプロイできます。

git clone https://github.com/making/hello-nodejs
cd hello-nodejs
tanzu apps workload create hello-nodejs \
  --local-path . \
  --source-image ghcr.io/${GITHUB_USERNAME}/src \
  --type web \
  -n demo -y

次のコマンドでログを追跡できます。

tanzu apps workload tail hello-nodejs -n demo 

次のコマンドでアプリの情報を取得できます。

$ tanzu apps workload get -n demo hello-nodejs
# hello-nodejs: Ready
---
lastTransitionTime: "2021-11-15T12:49:09Z"
message: ""
reason: Ready
status: "True"
type: Ready

Workload pods
NAME                                             STATE       AGE
hello-nodejs-00001-deployment-6cb54bc7c7-s5z84   Running     19s
hello-nodejs-build-1-build-pod                   Succeeded   56s

Workload Knative Services
NAME           READY   URL
hello-nodejs   Ready   http://hello-nodejs.demo.vcap.me

出力されたURLにアクセスします。

$ curl http://hello-nodejs.demo.vcap.me
Hello Tanzu!

以下はデモの録画です(URLは異なりますが、内容は同じです)。

tanzu-push-2

アプリケーションを更新したい場合は、ソースコード変更後に tanzu apps workload update -n demo hello-nodejs --local-path . -y


Tanzu Application Serviceの機能は他にもいろいろありますが、本記事では最も基本的な"Source to URL"の機能を試しました。


✒️️ Edit  ⏰ History  🗑 Delete