IK.AM

@making's tech note


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

🗃 {Dev/CaaS/Kubernetes/TAP}
🏷 Kubernetes 🏷 Cartographer 🏷 TKG 🏷 Tanzu 🏷 TAP 🏷 Knative 
🗓 Updated at 2021-11-21T12:00:50Z  🗓 Created at 2021-11-15T13:29:10Z   🌎 English Page

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

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

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

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

目次

インストール環境の確認

インストールするTKGはvSphere上に作られおり、Workerは 2core 8GB x 5nodeです。TAPをインストールするには余裕のあるリソースです。

$ kubectl get node -owide
NAME                           STATUS   ROLES                  AGE   VERSION            INTERNAL-IP      EXTERNAL-IP      OS-IMAGE                 KERNEL-VERSION   CONTAINER-RUNTIME
leopard-control-plane-vwmrh    Ready    control-plane,master   15m   v1.21.2+vmware.1   10.213.232.232   10.213.232.232   VMware Photon OS/Linux   4.19.198-1.ph3   containerd://1.4.6
leopard-md-0-684dc87ff-6fngf   Ready    <none>                 13m   v1.21.2+vmware.1   10.213.232.233   10.213.232.233   VMware Photon OS/Linux   4.19.198-1.ph3   containerd://1.4.6
leopard-md-0-684dc87ff-6wmjv   Ready    <none>                 13m   v1.21.2+vmware.1   10.213.232.234   10.213.232.234   VMware Photon OS/Linux   4.19.198-1.ph3   containerd://1.4.6
leopard-md-0-684dc87ff-d26mx   Ready    <none>                 13m   v1.21.2+vmware.1   10.213.232.235   10.213.232.235   VMware Photon OS/Linux   4.19.198-1.ph3   containerd://1.4.6
leopard-md-0-684dc87ff-gp7m7   Ready    <none>                 13m   v1.21.2+vmware.1   10.213.232.237   10.213.232.237   VMware Photon OS/Linux   4.19.198-1.ph3   containerd://1.4.6
leopard-md-0-684dc87ff-qt7lb   Ready    <none>                 13m   v1.21.2+vmware.1   10.213.232.236   10.213.232.236   VMware Photon OS/Linux   4.19.198-1.ph3   containerd://1.4.6

TKGインストール直後の状態から始めます。ここではLoad BalancerのServiceにはNSX Advanced Load Balancer (a.k.a AVI)が設定されていますが、Metal LBでも代用できます。

$ kubectl get pod -A
NAMESPACE     NAME                                                     READY   STATUS    RESTARTS   AGE
avi-system    ako-0                                                    1/1     Running   0          2m49s
kube-system   antrea-agent-9bgx7                                       2/2     Running   0          2m30s
kube-system   antrea-agent-9zdtr                                       2/2     Running   0          2m42s
kube-system   antrea-agent-j2dt7                                       2/2     Running   0          2m33s
kube-system   antrea-agent-n5wvm                                       2/2     Running   0          2m31s
kube-system   antrea-agent-px6tm                                       2/2     Running   0          2m33s
kube-system   antrea-agent-rtsd7                                       2/2     Running   0          2m36s
kube-system   antrea-controller-79fd6dbb89-8mdg7                       1/1     Running   0          2m42s
kube-system   coredns-8dcb5c56b-6p69x                                  1/1     Running   0          4m51s
kube-system   coredns-8dcb5c56b-pfl5j                                  1/1     Running   0          4m51s
kube-system   etcd-leopard-control-plane-vwmrh                         1/1     Running   0          4m56s
kube-system   kube-apiserver-leopard-control-plane-vwmrh               1/1     Running   0          4m56s
kube-system   kube-controller-manager-leopard-control-plane-vwmrh      1/1     Running   0          4m56s
kube-system   kube-proxy-9cd6w                                         1/1     Running   0          4m51s
kube-system   kube-proxy-bf62j                                         1/1     Running   0          2m33s
kube-system   kube-proxy-hsgf7                                         1/1     Running   0          2m36s
kube-system   kube-proxy-qsnsz                                         1/1     Running   0          2m31s
kube-system   kube-proxy-wlxjr                                         1/1     Running   0          2m33s
kube-system   kube-proxy-zt8b5                                         1/1     Running   0          2m30s
kube-system   kube-scheduler-leopard-control-plane-vwmrh               1/1     Running   0          4m56s
kube-system   metrics-server-6785d4b968-c5kxt                          1/1     Running   0          2m50s
kube-system   vsphere-cloud-controller-manager-8wb76                   1/1     Running   0          2m53s
kube-system   vsphere-csi-controller-57f464f799-265qz                  6/6     Running   0          2m9s
kube-system   vsphere-csi-node-2ptbc                                   3/3     Running   0          2m9s
kube-system   vsphere-csi-node-6hzc7                                   3/3     Running   0          2m9s
kube-system   vsphere-csi-node-b57w7                                   3/3     Running   0          2m8s
kube-system   vsphere-csi-node-d7qv7                                   3/3     Running   0          2m8s
kube-system   vsphere-csi-node-xf5qk                                   3/3     Running   0          2m8s
kube-system   vsphere-csi-node-zfv2k                                   3/3     Running   0          2m8s
tkg-system    kapp-controller-57799f67b-8lq8b                          1/1     Running   0          4m30s
tkg-system    tanzu-capabilities-controller-manager-6ff97656b8-nrrjl   1/1     Running   0          4m26s

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

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

$ 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 0.3はkapp-controllerのバージョンが0.29以上である必要があります。TKG 1.4に含まれるkapp controllerはバージョンが0.23なので、kapp-controllerを手動で入れ替えます。

TKGのWorkload Clusterのkapp controllerはManagement Clusterのkapp-controller(App CR)によってインストールされているので、手動の変更がreconciliation loopによって戻されないように、 Management Cluster側のApp CRにpauseの設定を行います。

kubectl patch --context <MANAGEMENT_CLUSTER>-admin@<MANAGEMENT_CLUSTER> app/<WORKLOAD-CLUSTER>-kapp-controller -n default -p '{"spec":{"paused":true}}' --type=merge

Workload Clusterのkapp controllerを削除し、新しいkapp controllerをインストールします。

kubectl delete deployment kapp-controller -n tkg-system
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 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です。registryの登録からpacakgeの情報を取得するのに少し時間がかかるので、登録直後は何も出力されないかもしれません。

$ 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

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: leopard.maki.lol

tap_gui:
  service_type: LoadBalancer
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-657b5dd8b7-rmhsx    1/1     Running   0          6m12s
app-live-view            application-live-view-server-5445569fc8-98mqs            1/1     Running   0          6m11s
app-live-view            appliveview-webhook-5bdd7d5f54-b65kg                     1/1     Running   0          6m11s
avi-system               ako-0                                                    1/1     Running   0          79m
build-service            build-pod-image-fetcher-47cm2                            5/5     Running   0          8m9s
build-service            build-pod-image-fetcher-bwz5k                            5/5     Running   0          8m10s
build-service            build-pod-image-fetcher-c48l2                            5/5     Running   0          8m8s
build-service            build-pod-image-fetcher-wq4dj                            5/5     Running   0          8m9s
build-service            build-pod-image-fetcher-x57rp                            5/5     Running   0          8m8s
build-service            cert-injection-webhook-5f69b9b568-5mnfj                  1/1     Running   0          8m12s
build-service            dependency-updater-controller-7bd78cdbf8-jgf55           1/1     Running   0          8m14s
build-service            secret-syncer-controller-58bfdc9c9b-cvm5f                1/1     Running   0          8m9s
build-service            warmer-controller-7846bd65bb-r76r6                       1/1     Running   0          8m12s
cartographer-system      cartographer-controller-78979d6c9c-vvzj9                 1/1     Running   0          8m14s
cert-manager             cert-manager-5766c87845-wqwqb                            1/1     Running   0          9m54s
cert-manager             cert-manager-cainjector-67b64c6574-sp4gh                 1/1     Running   0          9m54s
cert-manager             cert-manager-webhook-5757fc4d5b-8flc2                    1/1     Running   0          9m53s
contour-external         contour-56c88f5c84-hg2s9                                 1/1     Running   0          8m14s
contour-external         contour-56c88f5c84-j6tnz                                 1/1     Running   0          8m12s
contour-external         envoy-4twj2                                              2/2     Running   0          8m12s
contour-external         envoy-cp4d9                                              2/2     Running   0          8m12s
contour-external         envoy-p8p7h                                              2/2     Running   0          8m16s
contour-external         envoy-qsbb2                                              2/2     Running   0          8m14s
contour-external         envoy-xjnw8                                              2/2     Running   0          8m14s
contour-internal         contour-8645497b6d-bdztt                                 1/1     Running   0          8m14s
contour-internal         contour-8645497b6d-wcjdx                                 1/1     Running   0          8m12s
contour-internal         envoy-bcf64                                              2/2     Running   0          8m16s
contour-internal         envoy-lrmzv                                              2/2     Running   0          8m12s
contour-internal         envoy-ndxvg                                              2/2     Running   0          8m14s
contour-internal         envoy-s2gjq                                              2/2     Running   0          8m14s
contour-internal         envoy-xcmjb                                              2/2     Running   0          8m12s
conventions-system       conventions-controller-manager-d64c9fbf-6bgrf            1/1     Running   0          8m16s
default                  application-live-view-connector-5f77ff6f4-zrr8c          1/1     Running   0          6m12s
developer-conventions    webhook-6bd955475c-4grz5                                 1/1     Running   0          6m2s
flux-system              source-controller-59d57666fc-ftzs8                       1/1     Running   0          9m54s
image-policy-system      image-policy-controller-manager-76694cc4b9-9krtq         2/2     Running   0          9m8s
kapp-controller          kapp-controller-b8988c788-djdrw                          1/1     Running   0          29m
knative-discovery        controller-7ff84d7db5-qvtwl                              1/1     Running   0          7m46s
knative-discovery        webhook-6b8c959c74-w7zd5                                 1/1     Running   0          7m46s
knative-eventing         eventing-controller-65d494f445-dvwjp                     1/1     Running   0          8m9s
knative-eventing         eventing-webhook-7df787749c-5tlxf                        1/1     Running   0          7m25s
knative-eventing         eventing-webhook-7df787749c-xsrlg                        1/1     Running   0          8m9s
knative-eventing         imc-controller-7d7fdf57c9-p9v65                          1/1     Running   0          8m9s
knative-eventing         imc-dispatcher-5747484b58-7jdvz                          1/1     Running   0          8m7s
knative-eventing         mt-broker-controller-5f4c8856d4-js5j5                    1/1     Running   0          8m3s
knative-eventing         mt-broker-filter-7d4786f548-sq6ks                        1/1     Running   0          8m4s
knative-eventing         mt-broker-ingress-7d9cdb8cdb-ctdzb                       1/1     Running   0          8m3s
knative-eventing         rabbitmq-broker-controller-54578ddfb8-gp5vw              1/1     Running   0          8m2s
knative-serving          activator-5f6d4b646f-2h5zh                               1/1     Running   0          7m14s
knative-serving          activator-5f6d4b646f-4rp52                               1/1     Running   0          7m12s
knative-serving          activator-5f6d4b646f-x656r                               1/1     Running   0          7m25s
knative-serving          autoscaler-865b6d9f-4xt5k                                1/1     Running   0          7m25s
knative-serving          contour-ingress-controller-54c44cf58-fsbcz               1/1     Running   0          8m11s
knative-serving          controller-59f4bdf8fd-kwt4m                              1/1     Running   0          7m24s
knative-serving          net-certmanager-webhook-548f6d7b8b-f62ts                 1/1     Running   0          7m52s
knative-serving          networking-certmanager-cdfd6d79-887m7                    1/1     Running   0          7m53s
knative-serving          webhook-894655cc8-gk252                                  1/1     Running   0          7m25s
knative-serving          webhook-894655cc8-j6wcv                                  1/1     Running   0          7m14s
knative-sources          rabbitmq-controller-manager-84b99554c4-64sr5             1/1     Running   0          8m1s
knative-sources          rabbitmq-webhook-65574cd7b6-5b6jj                        1/1     Running   0          8m1s
kpack                    kpack-controller-7b6ff58954-zg7w2                        1/1     Running   0          8m16s
kpack                    kpack-webhook-5879549464-pgkk4                           1/1     Running   0          8m16s
kube-system              antrea-agent-9bgx7                                       2/2     Running   0          79m
kube-system              antrea-agent-9zdtr                                       2/2     Running   0          79m
kube-system              antrea-agent-j2dt7                                       2/2     Running   0          79m
kube-system              antrea-agent-n5wvm                                       2/2     Running   0          79m
kube-system              antrea-agent-px6tm                                       2/2     Running   0          79m
kube-system              antrea-agent-rtsd7                                       2/2     Running   0          79m
kube-system              antrea-controller-79fd6dbb89-8mdg7                       1/1     Running   0          79m
kube-system              coredns-8dcb5c56b-6p69x                                  1/1     Running   0          81m
kube-system              coredns-8dcb5c56b-pfl5j                                  1/1     Running   0          81m
kube-system              etcd-leopard-control-plane-vwmrh                         1/1     Running   0          81m
kube-system              kube-apiserver-leopard-control-plane-vwmrh               1/1     Running   0          81m
kube-system              kube-controller-manager-leopard-control-plane-vwmrh      1/1     Running   0          81m
kube-system              kube-proxy-9cd6w                                         1/1     Running   0          81m
kube-system              kube-proxy-bf62j                                         1/1     Running   0          79m
kube-system              kube-proxy-hsgf7                                         1/1     Running   0          79m
kube-system              kube-proxy-qsnsz                                         1/1     Running   0          79m
kube-system              kube-proxy-wlxjr                                         1/1     Running   0          79m
kube-system              kube-proxy-zt8b5                                         1/1     Running   0          79m
kube-system              kube-scheduler-leopard-control-plane-vwmrh               1/1     Running   0          81m
kube-system              metrics-server-6785d4b968-c5kxt                          1/1     Running   0          79m
kube-system              vsphere-cloud-controller-manager-8wb76                   1/1     Running   0          79m
kube-system              vsphere-csi-controller-57f464f799-265qz                  6/6     Running   18         79m
kube-system              vsphere-csi-node-2ptbc                                   3/3     Running   0          79m
kube-system              vsphere-csi-node-6hzc7                                   3/3     Running   0          79m
kube-system              vsphere-csi-node-b57w7                                   3/3     Running   0          79m
kube-system              vsphere-csi-node-d7qv7                                   3/3     Running   0          79m
kube-system              vsphere-csi-node-xf5qk                                   3/3     Running   0          79m
kube-system              vsphere-csi-node-zfv2k                                   3/3     Running   7          79m
scp-toolkit              scp-toolkit-controller-manager-6dd4c85c99-ll26t          1/1     Running   0          8m16s
secretgen-controller     secretgen-controller-6cf864d4df-kkdj4                    1/1     Running   0          26m
service-bindings         manager-765846778f-w9hgh                                 1/1     Running   0          8m11s
source-system            source-controller-manager-dfbd5fd-cg7xq                  1/1     Running   0          8m16s
spring-boot-convention   spring-boot-webhook-548c58f4b5-fsdv5                     1/1     Running   0          6m12s
stacks-operator-system   controller-manager-67994fc6dd-bhwtj                      1/1     Running   0          8m4s
tap-gui                  server-6f499f999f-7dlrs                                  1/1     Running   0          8m14s
tkg-system               tanzu-capabilities-controller-manager-6ff97656b8-nrrjl   1/1     Running   0          81m
triggermesh              aws-event-sources-controller-5b7ff6f567-9fcln            1/1     Running   0          7m23s
vmware-sources           webhook-7669895c9c-kfhvq                                 1/1     Running   0          7m51s

リソース使用状況は次の通りです。

$ kubectl top node
NAME                           CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
leopard-control-plane-vwmrh    895m         44%    4619Mi          58%       
leopard-md-0-684dc87ff-6fngf   184m         9%     2509Mi          31%       
leopard-md-0-684dc87ff-6wmjv   194m         9%     2414Mi          30%       
leopard-md-0-684dc87ff-d26mx   163m         8%     2367Mi          30%       
leopard-md-0-684dc87ff-gp7m7   149m         7%     2268Mi          28%       
leopard-md-0-684dc87ff-qt7lb   237m         11%    2159Mi          27%  

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

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)が受け付けます。このEnvoyのIPアドレスをDNSに登録します。

この手順はOptionalです。この設定がなくてもTAPを試すことはできます。

EnvoyのIPアドレスは次のコマンドで確認できます。

kubectl get svc -n contour-external envoy -ojsonpath='{.status.loadBalancer.ingress[0].ip}'

この記事では*.leopard.maki.lolがこのEnvoyのIPを指すようにDNSに次のAレコードを登録します。

image

Knativeがこのドメインを使用するように次の設定を行います。

kubectl patch configmap config-domain -n knative-serving --type merge --patch '{"data":{"leopard.maki.lol":""}}'
ClusterIssuerの設定と自動TLSの有効化

Knativeがcert-managerを使ってTLS証明証を払い出すように次の設定を行います。

この手順もOptionalです。この設定がなくてもTAPを試すことはできます。

kubectl patch configmap config-certmanager -n knative-serving --type merge --patch '{"data":{"issuerRef":"kind: ClusterIssuer\nname: letsencrypt-maki-lol"}}'
kubectl patch configmap config-network -n knative-serving --type merge --patch '{"data":{"autoTLS": "Enabled"}}'

ここでは事前に作成したletsencrypt-maki-lolという名前のClusterIssuerを設定しています。 このClusterIssuerの作成は以下のletsencrypt-cluster-issuer-azuredns.ymlazuredns-config.ymlから作成しています。 https://github.com/categolj/k8s-manifests/tree/main/common/cluster-issuer

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   https://hello.demo.leopard.maki.lol

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

$ curl https://hello.demo.leopard.maki.lol
Hello Tanzu!

対象のドメイン名に対して、cert-managerがLet's EncryptのTLS証明書を発行するのに初回は約1分かかります。それまではHTTPSではアクセスできず、HTTPでのみアクセスできます。

以下はデモの録画です。

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   https://hello-nodejs.demo.leopard.maki.lol

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

$ curl https://hello-nodejs.demo.leopard.maki.lol
Hello Tanzu!

以下はデモの録画です。

tanzu-push-2

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


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


✒️️ Edit  ⏰ History  🗑 Delete