Command Line Interface¶
The K9 CLI is designed to allow clusters to be created quickly and easily. Most commands are meant to run easily with opinionated defaults. The typical process for creating a cluster will be as follows:
cd into a directory where you will hold the CloudFormation files
k9 create templates
Edit the cluster-config.yml file. Edit cfm files as needed.
k9 create cluster
This will create stacks for certificates (which must be manually approved), the VPC, the EKS control plane, the EKS workers, and RDS. Next, standard apps EFK, Prometheus, and Grafana will be deployed to the cluster. If the clusterName provided in k9-config.yml contains ‘cicd’, standard cicd apps Jenkins, SonarQube, and Anchore will be deployed.
This directory can be used to recreate stacks exactly, so you may wish to keep it in some sort of version control. The values from cluster-config.yml will be wired into the cfm files when the stacks are made.
Commands¶
These are available command line commands from the k9 library. They are called with the format ‘k9 command resource’
- class k9.cli.CommandExecution[source]¶
Class that holds cli commands. Takes commands in the form ‘k9 command resource’ and calls function name command_resource()
- k9.cli.CommandExecution.create_project(*args, **kwargs)¶
The first command that is run when using k9. Creates the k9 directory and subdirectory structures.
- k9.cli.CommandExecution.create_templates(*args, **kwargs)¶
Copies default config and CloudFormation files from atomic-cloud into the current directory, skipping files that already exist.
- k9.cli.CommandExecution.create_cluster(*args, **kwargs)¶
Creates a cluster based on the k9-config and CloudFormation files in the current directory. If k9-config.yml is not present, it will prompt the user to run “k9 create templates”
If there is an error when creating stacks, you must call delete cluster to clean up all stacks.
- k9.cli.CommandExecution.deploy_service(*args, **kwargs)¶
Deploys the service application using the information in app-config.yml from the current directory, and helm values.yml files found in values/ in the current directory. Creates a values.yml file in values/ directory then reads it when calling helm install.
- k9.cli.CommandExecution.deploy_ui(*args, **kwargs)¶
Deploys the ui application using the information in app-config.yml from the current directory.
- k9.cli.CommandExecution.delete_cluster(*args, **kwargs)¶
Deletes a cluster with the given clusterName. Prompts user to delete certificates.
Usage: ‘k9 delete cluster -n clusterName’
‘k9 delete cluster -n clusterName -kc true’
- k9.cli.CommandExecution.delete_monitoring(*args, **kwargs)¶
Deletes EFK, Prometheus, Grafana default deployments from the cluster. Useful if you wish to use different helm charts for these apps.
Create Cluster Functions¶
These are the functions called by the create cluster command line command.
- k9.cluster_init.create_cluster(config, cwd: str)[source]¶
Called by create cluster cli. Does all cluster setup including CloudFormation stacks, installing standard apps, configuring standard apps, and create an access role for the cluster.
- Parameters
config – config dictionary as read from your cluster-config file
cwd – the current working directory that contains all the cfm template files
create_cluster() uses the atomic-cloud.cluster.create_cluster() to create AWS CloudFormation stacks based on the k9-config.yml and CloudFormation templates in the directory the command was run from.
After the stacks have been created, it will call install_standard_apps() and then if ‘cicd’ is present in the clusterName, it will call create_cicd().
Once this is all complete, there will be a fully complete cluster ready for your application deployment.
- k9.cluster_init.install_standard_apps(config)[source]¶
Called by
k9.cluster_init.create_cluster()
after creating the cluster. Deploys standard kubernetes apps: EFK, Grafana, Prometheus. Also adds dashboards to Kibana and Grafana.- Parameters
config – config dictionary as read from your cluster-config file
install_standard_apps() will deploy EFK, Prometheus, and Grafana using the SimonComputing helm charts.
- k9.cluster_init.create_cicd(config)[source]¶
Called by
k9.cluster_init.create_cluster()
if creating a cicd cluster. Deploys cicd apps: Jenkins and SonarQube
create_cicd() will deploy Jenkins, SonarQube, and Anchore using the SimonComputing helm charts.
SonarQube and Anchore require databases before installing the helm chart, so create_app_database will be used to make the databases for these two apps.
Next, kubectl must be configured to connect to the cluster and create the cicd namespace.
Then a PersistentVolumeClaim will be created for the Jenkins deployment. We keep this separate from the Jenkins helm chart so that we can uninstall and reinstall Jenkins without losing data.
Finally, the helm charts will be deployed with install_jenkins(), install_sonarqube(), and install_anchore().
- k9.cluster_init.install_efk(params: dict, namespace: str = 'logging')[source]¶
Installs EFK to the current kubernetes environment.
- Parameters
params – a dictionary containing the params to insert into the efk chart’s values.yaml
namespace – the namespace to install efk in. defaults to cluster-tools
- Returns
None on success, exception if failure.
- k9.cluster_init.install_prometheus(params: dict, namespace: str = 'monitoring')[source]¶
Installs Prometheus to the current kubernetes environment.
- Parameters
params – a dictionary containing the params to insert into the prometheus chart’s values.yaml
namespace – the namespace to install prometheus in. defaults to cluster-tools
- Returns
None on success, exception if failure.
- k9.cluster_init.install_grafana(params: dict, namespace: str = 'monitoring')[source]¶
Installs grafana to the current kubernetes environment.
- Parameters
params – a dictionary containing the params to insert into the grafana chart’s values.yaml
namespace – the namespace to install grafana in. defaults to cluster-tools
- Returns
None on success, exception if failure.
- k9.cluster_init.install_jenkins(params: dict, namespace='cicd')[source]¶
Installs Jenkins to the current kubernetes environment.
- Parameters
params – a dictionary containing the params to insert into the jenkins chart’s values.yaml
namespace – the namespace to install jenkins in. defaults to cluster-tools
- Returns
None on success, exception if failure.
- k9.cluster_init.install_sonarqube(params: dict, namespace: str = 'cicd')[source]¶
Installs SonarQube to the current kubernetes environment.
- Parameters
params – a dictionary containing the params to insert into the sonarqube chart’s values.yaml
namespace – the namespace to install sonarqube in. defaults to cluster-tools
- Returns
None on success, exception if failure.
Upcoming:
install_anchore