Package: idem-k8s
The Idem Kubernetes providerAboutAn Idem plugin to manage Kubernetes resources.What is POP?This project is built withpop, a Python-based implementation ofPlugin 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:Intro to Plugin Oriented Programming (POP)pop-awesomepop-createGetting StartedPrerequisitesPython 3.8+git(if installing from source or contributing to the project)To contribute to the project and set up your local development environment, seeCONTRIBUTING.rstin the source repository for this project.InstallationYou can installidem-k8swith the Python package installer (PyPI) or from source.Install from PyPIpipinstallidem-k8sInstall from source# Clone repogitclonegit@<your-project-path>/idem-k8s.gitcdidem-k8s# Set up venvpython3-mvenv.venvsource.venv/bin/activatepipinstall-e.DevelopmentTheidem-k8splugin 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-createk8s\--directory~/idem_k8s/autogen/dummy\# directory in which the generated state files are stored-tv\-nidem_k8s\--resourceapps/v1/DaemonSet# resource for which state files are generatedTheresourceargument follows the format:group/version/kindFor example, to add a resource state for Deployment, the argument is:apps/v1/DeploymentFor more information, see theKubernetes resource objects documentation.UsageSetupAfter installation,idem-k8sexecution and state modules are accessible to the pophub.For more information:Intro to Plugin Oriented Programming (POP)pop hubTo useidem-k8sexecution and state modules to manage cluster resources, you need to set up authentication in one of the following ways.With environment variablesSet KUBE_CONFIG_PATH and KUBE_CTX environment variables to the Kubernetes configuration file and context found in yourkube_configfile.In the Idem config fileEdit the Idem config file to include thekube_config_pathandcontextunder account extras. Use the following example as a guideline.acct:extras:k8s:default:kube_config_path:~/.kube/configcontext:defaultIn a credentials.yaml fileCreate or edit an Idem credentials.yaml file to add thekube_config_pathandcontextto a Kubernetes profile. Use the following example as a guideline.k8s:default:kube_config_path:~/.kube/configcontext:defaultFor more about Idem credentials files, including recommended steps for encryption and environment variables, seeAuthenticating with IdemYou are now ready to use idem-k8s.StatesIdem SLS files use states to ensure that resources are in a desired configuration. An idem-k8s SLS file supports three state functions:present,absent, anddescribe.presentThepresentfunction ensures that a resource exists. If a resource doesn’t exist, runningpresentcreates it. If the resource already exists, runningpresentmight leave it unchanged, or update it if there are any configuration changes.absentTheabsentfunction ensures that a resource does not exist. If the resource exists, runningabsentdeletes it. If the resource doesn’t exist, runningabsenthas no effect.describeThedescribefunction returns a list of all resources in the Kubernetes cluster of the same type as specified in the credential profile.Accessing StatesStates can be accessed by their relative location inidem-k8s/k8s/states.For example, a Kubernetes deployment state can be created with thepresentfunction as shown in the following SLS file.k8s_deployment.sls:nginx-deployment:k8s.apps.v1.deployment.present:-metadata:name:nginx-deploymentnamespace:default-spec:replicas:3selector:match_labels:app:nginxstrategy:rolling_update:max_surge:25%max_unavailable:25%type:RollingUpdatetemplate:metadata:labels:app:nginxspec:containers:-image:nginx:1.14.20image_pull_policy:IfNotPresentname:nginxports:-container_port:80protocol:TCPtermination_message_path:/dev/termination-logtermination_message_policy:Filerestart_policy:AlwaysThe Idem command to create the preceding deployment state is:idemstate$PWD/k8s_deployment.slsCurrent Supported Resourcesapiregistration_k8s_io.v1api_serviceapps.v1daemon_setdeploymentcore.v1config_mapnamespacesecretservice_accountservicepersistent_volume_claimrbac.v1cluster_rolecluster_role_bindingrole_bindingstorage_k8s_io.v1storage_class