Skip to main content

No project description provided

Project description

Kubernetes provider for Idem

About

Idem plugin to manage Kubernetes resources

What is POP?

This project is built with pop, a Python-based implementation of Plugin Oriented Programming (POP). POP seeks to bring together concepts and wisdom from the history of computing in new ways to solve modern computing problems.

For more information:

Getting Started

Prerequisites

  • Python 3.6+

  • git (if installing from source, or contributing to the project)

Installation

If wanting to use idem-k8s, you can do so by either installing from PyPI or from source.

Install from PyPI

pip install idem-k8s

Install from source

# clone repo
git clone git@<your-project-path>/idem-k8s.git
cd idem-k8s

# Setup venv
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Development

idem-k8s has built-in auto code generation to extend support for additional kubernetes resources. Kubernetes resource state file can be auto generated by running the following command :

pop-create k8s \
--directory ~/idem_k8s/autogen/dummy \  # directory in which the generated state files are stored
-tv \
-n idem_k8s \
--resource apps/v1/DaemonSet  # resource for which state files are generated

The k8s state auto code generation generates over 90% of code required to support a new kubernetes resource.

Usage

Setup

After installation, the k8s Idem execution and state modules will be accessible to the pop hub. In order to use them, we need to set up our credentials.

For more information:

Create a new file called credentials.yaml and populate it with credentials. The default profile will be picked up automatically by idem.

credentials.yaml:

k8s:
  default:
    kube_config_path: ~/.kube/config
    context: default

Next step is to encrypt the credentials file, and add the encryption key and encrypted file path to the ENVIRONMENT.

Encrypt the credential file:

Idem encrypt credentials.yaml

This will generate a credentials.yaml.fernet file and a command line output token:

-AXFSEFSSEjsfdG_lb333kVhCVSCDyOFH4eABCDEFNwI=

Add these to your environment:

export ACCT_KEY="-AXFSEFSSEjsfdG_lb333kVhCVSCDyOFH4eABCDEFNwI="
export ACCT_FILE=$PWD/credentials.yaml.fernet

You are ready to use idem-k8s!!!

States

Idem states are used to make sure resources are in a desired state. The desired state of a resource can be specified in sls file. In Idem-k8s, three states are supported: present, absent, describe

present state

present state makes sure a resource exists in a desired state. If a resource does not exist, running present will create the resource on the provider. If a resource exists, running present will update the resource on the provider.

absent state

absent state makes sure a resource does not exist. If a resource exits, running absent will delete the resource. If a resource does not exist, running absent is a no-operation.

describe state

describe state lists all the current resources of the same resource type in the k8s cluster specified in the credential profile.

States can be accessed by their relative location in idem-k8s/idem_k8s/states. For example, in the state sls yaml file below, k8s deployment state can be created with the present function.

k8s_deployment.sls:

nginx-deployment:
  k8s.apps.v1.deployment.present:
  - metadata:
      name: nginx-deployment
      namespace: default
  - spec:
      replicas: 3
      selector:
        match_labels:
          app: nginx
      strategy:
        rolling_update:
          max_surge: 25%
          max_unavailable: 25%
        type: RollingUpdate
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - image: nginx:1.14.20
            image_pull_policy: IfNotPresent
            name: nginx
            ports:
            - container_port: 80
              protocol: TCP
            termination_message_path: /dev/termination-log
            termination_message_policy: File
          restart_policy: Always

The state sls file can be executed with:

idem state $PWD/k8s_deployment.sls

Current Supported Resources

apps.v1

daemon_set

deployment

core.v1

config_map

namespace

secret

service_account

rbac.v1

cluster_role

cluster_role_binding

storage_k8s_io.v1

storage_class

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

idem-k8s-0.1.0.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

idem_k8s-0.1.0-py3-none-any.whl (50.0 kB view details)

Uploaded Python 3

File details

Details for the file idem-k8s-0.1.0.tar.gz.

File metadata

  • Download URL: idem-k8s-0.1.0.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.1 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.12.0 keyring/23.9.3 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.14

File hashes

Hashes for idem-k8s-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ca358a00eb58f2bcaf9ed7b3b3801a962060002af9b5865a7d70da04bac26d0c
MD5 657180d6adc8d51dba9ca2096fa89d86
BLAKE2b-256 7df9a78618dd0012eb842c03f02137c9aa318dad3b599b2fdadb3a99484c0745

See more details on using hashes here.

File details

Details for the file idem_k8s-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: idem_k8s-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 50.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.1 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.12.0 keyring/23.9.3 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.14

File hashes

Hashes for idem_k8s-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6d9a32c92eb3fc5c86422477b8900dd905833286b798f6988b93088312a0bbd
MD5 ba50d25fc9963b54d9bccb8b06314196
BLAKE2b-256 ee546ef064852b57d1b63c98d0e1ab46d3c75b399a4e845a3d6814e340ec7021

See more details on using hashes here.

Supported by

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