Skip to main content

Easy customization of kubernetes manifests

Project description

ksux

A simple way for templating kubernetes manifests.

Requirements

This is a python package. So the only requirements are python3 and pip

Installation

  • Optional: Create a virtual env.
# option 1: virualvenv
virtualvenv ksux
source ksux/bin/activate

# option 2: venv
python -m venv ksux
source ksux/bin/activate

# option 3: conda
conda create -n ksux python
conda activate ksux
  • Install
pip install ksux

How does it work?

tldr.

ksux -b <path_to_base_dir> -p <path_to_patches_dir> -o <output_dir>

Let's say that you have many manifests in some directory (base directory) that you wish to patch with patches (in the patches) directory.

Patches could be in yaml or json format (as well as your manifests). However, they must adhere to following schema:

name: <patch_description>
target:
  apiVersion: <apiVersion of targeted resource>
  kind: <Deployment type of targeted resource>
  name: <name of targeted resource>
ops:
  - name: <operation description>
    path: <path to the part of the manifest to be patched>
    value: <value which should be replaced or added>
    action: <add|replace|remove>

each patch file must be a list of patches. E.g.:

- name: deployment_patches
  target:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  ops:
    - name: replace_image
      path: /spec/template/spec/containers/nginx/image
      value: nginx:1.23
      action: replace
- name: service_patches
  target:
    apiVersion: v1
    kind: Service
    name: nginx-service
  ops:
    - name: add_https_port
      path: /spec/ports
      value:
        name: https
        port: 443
        protocol: TCP
        targetPort: 443
      action: add
    - name: rename_http_port
      path: /spec/ports/http/name
      action: replace
      value: new_name

Then all you need to do, is run:

ksux -b <path_to_base_dir> -p <path_to_patches_dir> -o <output_dir>

This will save all patched manifests to the output dir. You can use the --dry-run flag

ksux -b <path_to_base_dir> -p <path_to_patches_dir> --dry-run

For list of all options see:

ksux --help

the op path

This is a pretty cool thing. Similar to kustomize path, however you can target list item by names of child objects. E.g. say you have a list of ports in a service:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx-service
  name: nginx-service
spec:
  ports:
    - name: new_name
      port: 80
      protocol: TCP
      targetPort: 80
    - name: https
      port: 443
      protocol: TCP
      targetPort: 443
  selector:
    app: web
  type: ClusterIP

To target the https service and change its name, you can specify the path: /spec/ports/https/name and then set the value to the new name 💪.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ksux-0.3.9.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

ksux-0.3.9-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file ksux-0.3.9.tar.gz.

File metadata

  • Download URL: ksux-0.3.9.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for ksux-0.3.9.tar.gz
Algorithm Hash digest
SHA256 a7ddbf3b4a6903bfc11058dd205a52e53b52cb57cf83a6bf3f2e5bdaab9de8b9
MD5 5f7de5ec8cd1dd294158315cc71b7d4f
BLAKE2b-256 3783b6377e67f73a34235705cb6c14d6919cc6d29d65c4398836707759b5c57a

See more details on using hashes here.

File details

Details for the file ksux-0.3.9-py3-none-any.whl.

File metadata

  • Download URL: ksux-0.3.9-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for ksux-0.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 65c065708abad3116171bf853761d758f9b3737ea5a3fcd3b6ece7cd123bfea6
MD5 5ce7c0b4527782d59fdb79852802a967
BLAKE2b-256 b10c3d8b8d69da9ecd64baa4e73f529361bfdcabbfaa5c7ac19e0175dadc2b77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page