Clusters

Settings

These are the default provisioning settings that ModusKube uses when creating or replacing a cluster and are stored in /moduskube/ansible/inventory/group_vars/all/main.yml inside the container. They can be overridden on the command-line or when calling the API.

wait_for_startup: yes
shared_path: /shared

# AWS
aws_partition: aws
ec2_region: "{{ lookup('env', 'MODUSKUBE_REGION') }}"
ec2_az: '{{ ec2_region }}a'
ssh_user: core
node_ssh_key_name: moduskube-clusters
node_ssh_secret_name: /ModusKube/SSH/PrivateKeys/Node
node_ami_id: ami-0044ad4295abefc56 # Container Linux 2247.5.0

# Master
master_asg_name: '{{ cluster }} Masters'
master_sec_group_name: '{{ cluster }} Master'
master_ami_id: '{{ node_ami_id }}'
master_count: 1
master_instance_type: t3.medium
master_volume_type: gp2
master_volume_size: 50

# Worker
worker_asg_name: '{{ cluster }} Workers'
worker_sec_group_name: '{{ cluster }} Worker'
worker_ami_id: '{{ node_ami_id }}'
worker_count: 1
worker_instance_type: t3.medium
worker_volume_type: gp2
worker_volume_size: 25

# Bastion server
bastion_enabled: "{{ network_subnet_type == 'private' }}"
bastion_sec_group_name: '{{ cluster }} Bastion'
bastion_asg_name: '{{ cluster }} Bastion'
bastion_name: '{{ cluster }} Bastion'
bastion_ami_id: '{{ node_ami_id }}'
bastion_instance_type: t3.medium
bastion_ssh_key_name: '{{ node_ssh_key_name }}'

# Networking
network_configure: yes
network_cni_release: v0.8.2
network_pod_cidr: 192.168.0.0/16
network_vpc_name: ModusKube Clusters
network_vpc_cidr: 10.0.0.0/16
network_private_subnet_cidr: 10.0.0.0/24
network_private_admin_subnet_cidr: 10.0.100.0/24
network_public_subnet_cidr: 10.0.1.0/24
network_cluster_ownership: shared
network_subnet_type: public

# Kubernetes
k8s_release: v1.15.5
k8s_home: /opt/kubernetes
k8s_api_server_cert_sans:
  public:
    - localhost
    - ${COREOS_EC2_IPV4_PUBLIC}
  private:
    - localhost

# Versions
cli53_release: v0.8.12

# S3
k8s_bucket: modusbox-k8s
charts_bucket: modusbox-charts
cluster_state_bucket: "{{ lookup('env', 'MODUSKUBE_STATE_BUCKET') }}"
cluster_state_bucket_versioning: yes
cluster_state_path: '{{ cluster }}'
cluster_state_url: 's3://{{ cluster_state_bucket }}/{{ cluster_state_path }}'

# Bootstrap
bootstrap_path: /opt/bin/bootstrap
bootstrap_log_path: /var/log/bootstrap.log
bootstrap_python_packages:
  - awscli
  - boto3
  - docker
  - httpie

# kudeaadm
kubeadm_conf_path: /etc/kubernetes/kubeadm.conf
kubeadm_token_ttl: 0s

# Python
ansible_python_interpreter: /opt/pypy/bin/pypy
pypy_version: 5.10.0

# Slack
slack_max_log_chars: 3000

Classes

class moduskube.resources.cluster.Cluster(name: Optional[str] = None, *args, region: str = 'us-west-2', varsfiles: Optional[Sequence[str]] = None, **kwargs)

Create and manage Kubernetes clusters.

This class represents a Kubernetes cluster and is the primary high-level API for cluster management. A cluster instance is uniquely identified by its name.

Parameters
  • name – The name of the cluster. The name should be in “kabob-case” (e.g. my-cluster).

  • region – The AWS region that all operations on this cluster should take place in.

  • varsfiles – Paths to YAML or JSON files containing extra variables to pass to Ansible during provisioning operations.

create(wait: bool = True, validate: bool = True, ssh_secret_names: Optional[Union[str, Sequence[str]]] = None, force_create: bool = False, **extravars) Tuple[int, str, str]

Create a new Kubernetes cluster.

Parameters
  • wait – Wait for cluster to be fully provisioned before returning.

  • validate – Run cluster validation test suite after creation.

  • ssh_secret_names – Names of private key secrets to load for SSH operations.

  • force_create – Force creation of cluster even if state already exists.

  • extravars – Extra variables to pass to Ansible during cluster provisioning. See Settings for available variables and defaults.

Examples

from moduskube.resources.cluster import Cluster

cluster = Cluster('my-cluster', region='us-east-1')

# Create a cluster using default settings
cluster.create()

# Create a cluster with a custom worker instance type and count
cluster.create(worker_instance_type='m5.large', worker_count=5)

Tip

See Settings for all the options you can override when creating a cluster.

get_addresses(role: moduskube.utils.ClusterRole, client=None) Optional[Sequence[moduskube.resources.cluster.Addresses]]

Get network addresses for the specified role.

Looks for all cluster VMs where the instance tag moduskube/role matches role.

Parameters
  • role – The VM role used to query for IP addresses. Must be master or bastion.

  • client – A boto3 Client instance.

Returns

List of Addresses instances, one for each matching VM.

get_instance_id(role: moduskube.utils.ClusterRole, client=None) str

Get instance ID for the specified role.