A command line tool for pushing docker images referenced in Kubernetes yaml files into a custom Docker registry. The name korp
derives from combining the customary shorthand for "corporation" with a k for Kubernetes. The name was chosen because corporate Docker registries are the main use case for the tool.
Current version: 1.0.2
- Download the latest release and unpack it
- Add the
korp
binary to your PATH
korp
has three commands for 1. scanning yaml files, 2. pulling the referenced images and 3. pushing them to the new registry. Patching the yaml files for deployment is delegated to kustomize
and kubectl apply -k
since this is a well-established tool set for last-mile customization of Kubernetes yaml files.
The scan
command recursively scans a directory, collects all references to Docker images and creates a kustomization.yml
file consisting of an images
section.
The following command will scan the templates
directory (and its sub-directories) and create an images
entry in kustomization.yml
for each image reference found where the newName
field is the normalized image name prefixed with my-registry.example.org
.
korp scan -f ./templates -r my-registry.example.org
The pull
command will read the kustomization.yml
file generated by the scan
command and pull all original images to the local Docker daemon i.e. the Docker daemon which is running on the machine where korp
is executed.
The following command pulls all images referenced by the name
attribute of the elements of the images
list in the kustomization.yml
file in the current directory.
korp pull
The push
command will read the kustomization.yml
file generated by the scan
command, tag all referenced images with their new name (including the new registry) and push them. The command assumes that scan
and pull
have already been executed.
The following command tags each image according to the newName
attribute in the corresponding entry of the images
list and pushes all images.
korp push
korp
delegates the actual patching of the image references in the YAML files to kustomize
. You can use the following steps to apply the kustomization.yaml
generated by korp
to your YAML files.
-
Add the required resources to the
kustomization.yaml
. The set of resources depends on your use case. If you want to add allyaml
files which were scanned bykorp
(excluding thekustomization.yaml
itself) you can use the following glob pattern.kustomize edit add resource **/!(kustomization).yaml;
-
Apply your YAML files with
kubectl
.kubectl apply -k .
Let's look at how to use korp
on a real world example. Let's assume you want to deploy Istio in a corporate environment which has its own Docker registry. These are the steps which you would need to execute.
At the time of writing Istio is deployed using two Helm charts istio-init
and istio
. Since korp
works with yaml files, you need to first render these two charts against your values.yml
files using the command helm template
.
- Clone the Istio repo
git clone https://github.com/istio/istio.git
cd istio
-
Make the desired changes to
install/kubernetes/helm/istio-init/values.yaml
andinstall/kubernetes/helm/istio/values.yaml
. You can ignore the fact that thehub
attributes in these files point to public registries. This will be patched with the help ofkorp
after the yaml files are rendered. -
Render the Helm charts to two directories.
mkdir $HOME/tmp/istio-init
mkdir $HOME/tmp/istio
helm template install/kubernetes/helm/istio-init --name istio-init --namespace istio-system --output-dir $HOME/tmp/istio-init
helm template install/kubernetes/helm/istio --name istio --namespace istio-system --output-dir $HOME/tmp/istio
- Scan the
istio-init
yaml files. You will see akustomization.yml
file being created with oneimages
entry.
cd $HOME/tmp/istio-init/istio-init
korp scan . -r your-registry.example.org
- Scan the
istio
yaml files. You will see akustomization.yml
file being created with variousimages
entries.
cd $HOME/tmp/istio/istio
korp scan . -r your-registry.example.org
- Pull the
istio-init
images.
cd $HOME/tmp/istio-init/istio-init
korp pull
- Pull the
istio
images.
cd $HOME/tmp/istio/istio
korp pull
- Push the
istio-init
images. Depending on your network and proxy setup, you might need to change your network connection.
cd $HOME/tmp/istio-init/istio-init
korp push
- Push the
istio
images.
cd $HOME/tmp/istio/istio
korp push
- Apply the yaml files for
istio-init
usingkustomize
cd $HOME/tmp/istio-init/istio-init
kubectl create ns istio-system
kustomize edit add resource **/!(kustomization).yaml
kubectl apply -k .
- Apply the yaml files for
istio
usingkustomize
cd $HOME/tmp/istio/istio
kustomize edit add resource **/!(kustomization).yaml
kubectl apply -k .
Source the autocomplete-scripts/*_autocomplete
file in your .bashrc | .zshrc
file while setting the PROG
variable to the name of your program.
go build .
source <(./korp autocompletion zsh)
./korp
# now play with tab
go build .
PROG=korp source autocomplete-scripts/zsh_autocomplete
./korp
# now play with tab