Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
/ k8spkg Public archive

A Kubernetes component lifecycle manager CLI (deprecated in favour of kpt)

License

Notifications You must be signed in to change notification settings

mgoltzsche/k8spkg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k8spkg Build Status Go Report Card

A wrapper around kubectl to transform, deploy, undeploy and retrieve Kubernetes manifests as a deployment unit waiting for the respective task to be completed. k8spkg accepts manifest files and kustomizations like kubectl.

Features

  • Maintain a group of Kubernetes resources as package using labels (app.kubernetes.io/part-of, k8spkg.mgoltzsche.github.com/namespaces).
  • Add common labels to a manifest's resources (using kustomize).
  • Wait for conditions (ready, available, ...) of a manifest's resources.
  • List installed packages: Packages are visible within their resources' namespace(s) only as long as they don't have cluster-scoped resources as well.
  • Delete resources by package name or manifest and wait until they are deleted.
  • kustomization source support.

Requirements

Usage

Command Description
manifest {-f SRC|-k SRC} [--name <PKG>] [--namespace <NS>] [--timeout <DURATION>] Prints a merged and labeled manifest
apply {-f SRC|-k SRC} [--name <PKG>] [--namespace <NS>] [--timeout <DURATION>] [--prune] Installs or updates the provided source as package and waits for the rollout to succeed. --prune deletes all resources labeled with the package name that do not appear within the source from the cluster - should be used carefully.
delete {-f SRC|-k SRC|PKG} [--namespace <NS>] [--timeout <DURATION>] Deletes the identified resources from the cluster and awaits their deletion. A package's resources in other namespaces that are referred to (label) within cluster-scoped resources are deleted as well.
list [--all-namespaces|--namespace <NS>] [--timeout <DURATION>] Lists the installed packages that are visible within the namespace. Other namespaces are not queried as long as --all-namespaces is not enabled. However packages of cluster-scoped resources and their referenced (label) namespaces are listed as well.

Examples

Print labeled manifest of the deployment unit cert-manager:

$ k8spkg manifest --name cert-manager -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.7/deploy/manifests/cert-manager.yaml
<YAML output>

Label and deploy cert-manager and a namespaced issuer afterwards:

k8spkg apply --name cert-manager -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.7/deploy/manifests/cert-manager.yaml &&
k8spkg apply --name cert-manager-ca-issuer -f ca-issuer.yaml

Please note that this does not (yet?!) work with kubectl apply since it does not wait for resources to be ready (cert-manager's APIService must accept the Issuer) and there is no option or other generic kubectl command to wait for such a state based on a given manifest. Fortunately kubectl rollout and kubectl wait serve this purpose but require resource names and type-dependent options which k8spkg provides.

List the installed packages from within the default namespace:

$ k8spkg list
PACKAGE                   NAMESPACES
cert-manager              cert-manager,kube-system

List the installed packages wtthin cert-manager namespace:

$ k8spkg list -n cert-manager
PACKAGE                   NAMESPACES
cert-manager              cert-manager,kube-system
cert-manager-ca-issuer    cert-manager

Label and deploy a kustomize package:

k8spkg apply --name hello-world -k github.com/kubernetes-sigs/kustomize//examples/helloWorld?ref=v2.1.0

Install or update a package in another namespace:

k8spkg apply -n mynamespace --name hello-world --prune -k github.com/kubernetes-sigs/kustomize//examples/helloWorld?ref=v2.1.0

Delete a previously installed package:

k8spkg delete -n cert-manager cert-manager-ca-issuer

Install

Download and install the latest k8spkg release (static linux amd64):

curl -L https://github.com/mgoltzsche/k8spkg/releases/latest/download/k8spkg > k8spkg
chmod +x k8spkg
sudo mv k8spkg /usr/local/bin/k8spkg

Build

Install/update with Go:

go get -u github.com/mgoltzsche/k8spkg

or run a dockerized k8spkg build:

git clone https://github.com/mgoltzsche/k8spkg
cd k8spkg && make
sudo mv k8spkg /usr/local/bin/

The project can be opened in a containerized LiteIDE using make ide.

License

k8spkg is licensed under Apache License 2.0. Some of the 3rd party modules in the vendor directory are licensed under different Open Source conditions (see LICENSE files).