Skip to main content

No project description provided

Project description

The Idem Kubernetes provider

About

An 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.7+

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

    To contribute to the project and set up your local development environment, see CONTRIBUTING.rst in the source repository for this project.

Installation

You can install idem-k8s with the Python package installer (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

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

Development

The idem-k8s plugin has built-in automatic code generation to extend support for additional Kubernetes resources. Automatic code generation creates over 90% of the code required to support a new Kubernetes resource.

Automatically generate a Kubernetes resource state file with 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 resource argument follows the format: group/version/kind

For example, to add a resource state for Deployment, the argument is: apps/v1/Deployment

For more information, see the Kubernetes resource objects documentation.

Usage

Setup

After installation, idem-k8s execution and state modules are accessible to the pop hub.

For more information:

To use idem-k8s execution and state modules to manage cluster resources, you need to set up authentication in one of the following ways.

With environment variables

Set KUBE_CONFIG_PATH and KUBE_CTX environment variables to the Kubernetes configuration file and context found in your kube_config file.

In the Idem config file

Edit the Idem config file to include the kube_config_path and context under account extras. Use the following example as a guideline.

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

In a credentials.yaml file

Create or edit an Idem credentials.yaml file to add the kube_config_path and context to a Kubernetes profile. Use the following example as a guideline.

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

For more about Idem credentials files, including recommended steps for encryption and environment variables, see Authenticating with Idem

You are now ready to use idem-k8s.

States

Idem SLS files use states to ensure that resources are in a desired configuration. An idem-k8s SLS file supports three state functions: present, absent, and describe.

present

The present function ensures that a resource exists. If a resource doesn’t exist, running present creates it. If the resource already exists, running present might leave it unchanged, or update it if there are any configuration changes.

absent

The absent function ensures that a resource does not exist. If the resource exists, running absent deletes it. If the resource doesn’t exist, running absent has no effect.

describe

The describe function returns a list of all resources in the Kubernetes cluster of the same type as specified in the credential profile.

Accessing States

States can be accessed by their relative location in idem-k8s/k8s/states.

For example, a Kubernetes deployment state can be created with the present function as shown in the following SLS file.

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 Idem command to create the preceding deployment state is:

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.2.0.tar.gz (31.2 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.2.0-py3-none-any.whl (50.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: idem-k8s-0.2.0.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.2 requests/2.28.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.9.3 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.15

File hashes

Hashes for idem-k8s-0.2.0.tar.gz
Algorithm Hash digest
SHA256 58c66bd7b65b60e4545aae438ca36c3cab654eed8b21fb59506338794c7603ef
MD5 0fd7ab41a81104cba1772f504ba2556a
BLAKE2b-256 fd7308dc8ee8c8b354c9501c4a321bba6173b7c6c4485ba703873ddc41cd345c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for idem_k8s-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 834ac3951f49b35cc5db475ce99e443128ed0055fd21e3db92a1b549a65f5c21
MD5 22a87c7e980292b23f7af5ae2b71ea0a
BLAKE2b-256 a471dd54c685e5f42dc507e81a119d4997387d1e5d6493d84c81563727a15f20

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