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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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