Consume a package with subpackages
Notice: Subpackages support is available with kpt version v0.34.0+ for [cfg] commands only
This guide walks you through an example to get, view, set and apply contents of an example kpt package with a subpackage in its directory tree.
Fetch a remote package
kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/wordpress \ wordpress
View the package contents
The primary package artifacts are Kubernetes resource configuration (e.g. YAML files).
List package contents in a tree structure
List the local package contents using the tree command.
kpt cfg tree wordpress/
wordpress ├── [Kptfile] Kptfile wordpress ├── [wordpress-deployment.yaml] Deployment wordpress ├── [wordpress-deployment.yaml] Service wordpress ├── [wordpress-deployment.yaml] PersistentVolumeClaim wp-pv-claim └── Pkg: mysql ├── [Kptfile] Kptfile mysql ├── [mysql-deployment.yaml] PersistentVolumeClaim mysql-pv-claim ├── [mysql-deployment.yaml] Deployment wordpress-mysql └── [mysql-deployment.yaml] Service wordpress-mysql
There are two kpt packages in the output:
mysql package is a subpackage of
List setters in the package
kpt cfg list-setters wordpress/
wordpress/ NAME VALUE SET BY DESCRIPTION COUNT REQUIRED gcloud.core.project PROJECT_ID 3 No image wordpress 1 No tag 4.8 1 No teamname YOURTEAM 3 Yes wordpress/mysql/ NAME VALUE SET BY DESCRIPTION COUNT REQUIRED gcloud.core.project PROJECT_ID 3 No image wordpress 1 No tag 4.8 1 No teamname YOURTEAM 3 Yes
You may notice that the auto-setter
gcloud.core.project is already set if you
gcloud configured on your local.
Provide the setter values
Provide the values for all the required setters. By default, set
command is performed only on the resource files of provided package and not its
--recurse-subpackages(-R) can be leveraged to run the command on
kpt cfg set wordpress/ teamname myteam -R
wordpress/ set 3 field(s) wordpress/mysql/ set 3 field(s)
Apply the package
Now that you have configured the package, apply it to the cluster
kubectl apply -f wordpress/ -R
service/wordpress-mysql created persistentvolumeclaim/mysql-pv-claim created deployment.apps/wordpress-mysql created service/wordpress created persistentvolumeclaim/wp-pv-claim created deployment.apps/wordpress created