Get a remote package
Any git directory containing configuration files may be used by kpt as a package.
kpt pkg get explained
Following is a short explanation of the command that will be demonstrated in this guide.
- Get copies the
staging/cockroachdbsubdirectory from the kubernetes examples git repo
- Since a Kptfile is not included with the package, a new one is created for the local package
- (Optional) commit the package and push to the team git repo
- Apply the package to a cluster
- May be pushed from the local package copy (manual) or from the team repo (GitOps automation)
- Fetch a remote package
- View the Kptfile
- View the package contents
- Apply the package to a cluster
- View the applied package
Fetch a remote package
kpt pkg get https://github.com/kubernetes/examples/staging/cockroachdb cockroachdb
fetching package staging/cockroachdb from https://github.com/kubernetes/examples to cockroachdb
The contents of the
staging/cockroachdb subdirectory in the
https://github.com/kubernetes/examples were copied to the local folder
- Any git subdirectory containing configuration (e.g.
deploy.yaml) may be fetched and used as a package
- The local directory name that the package is copied to does NOT need to match the upstream directory name it is copied from
.gitas part of the repo name is optional but good practice to ensure the repo + subdirectory are parsed correctly by the tool.
- Packages inside the same repo can be versioned individually by creating tags
with the format
<path to package in repo>/<version>, similar to how go modules are versioned. For example, a tag named
staging/cockroachdb/v1.2.3would be interpreted by kpt as version
v1.2.3of the cockroachdb package.
View the Kptfile
The upstream commit and branch / tag reference are stored in the package’s
Kptfile. These are used by
kpt pkg update.
Kptfile written by
kpt pkg get to see the upstream package data.
apiVersion: kpt.dev/v1alpha1 kind: Kptfile metadata: name: cockroachdb upstream: type: git git: commit: 629c9459a9f25e468cce8af28350a03e62c5f67d repo: https://github.com/kubernetes/examples directory: staging/cockroachdb ref: master
View the package contents
The primary package artifacts are Kubernetes resource configuration (e.g. YAML files), however packages may also include supporting artifacts such as documentation.
Package Contents Command
kpt cfg tree cockroachdb/
Package Contents Output
cockroachdb ├── [cockroachdb-statefulset.yaml] Service cockroachdb ├── [cockroachdb-statefulset.yaml] StatefulSet cockroachdb ├── [cockroachdb-statefulset.yaml] PodDisruptionBudget cockroachdb-budget └── [cockroachdb-statefulset.yaml] Service cockroachdb-public
The cockroachdb package fetched from kubernetes examples contains a
cockroachdb-statefulset.yaml file with the resource configuration, as well
as other files included in the directory.
kpt pkg get created a
Kptfile since one did not exist
(for storing package state). If the upstream package already defines a
kpt pkg get will update the
Kptfile copied from
upstream rather than replacing it.
apiVersion: v1 kind: Service metadata: # This service is meant to be used by clients of the database. It exposes a # ClusterIP that will automatically load balance connections to the different # database pods. name: cockroachdb-public labels: app: cockroachdb spec: ports:
This package contains
cockroachdb/cockroachdb-statefulset.yaml as plain old
resource configuration (e.g. YAML) – nothing special here. Other kpt packages
may have configuration which uses comments to attach metadata to
specific resources or fields.
Apply the package to a cluster
kubectl apply to deploy the local package to a remote cluster.
kubectl apply -R -f cockroachdb
service/cockroachdb-public created service/cockroachdb created poddisruptionbudget.policy/cockroachdb-budget unchanged statefulset.apps/cockroachdb created
This guide used
kubectl apply to demonstrate how kpt packages work out of the
box with tools that have been around since the beginning of Kubernetes.
Kpt also provides the next-generation set of Kubernetes apply commands under the [kpt live] command.
View the applied package
Once applied to the cluster, the remote resources can be displayed using common
tools such as
Applied Package Command
kubectl get all
Applied Package Output
NAME READY STATUS RESTARTS AGE pod/cockroachdb-0 1/1 Running 0 54s pod/cockroachdb-1 1/1 Running 0 41s pod/cockroachdb-2 1/1 Running 0 27s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/cockroachdb ClusterIP None <none> 26257/TCP,8080/TCP 55s service/cockroachdb-public ClusterIP 10.48.2.5 <none> 26257/TCP,8080/TCP 55s service/kubernetes ClusterIP 10.48.0.1 <none> 443/TCP 26m NAME READY AGE statefulset.apps/cockroachdb 3/3 54s