This example demonstrates how to deploy nodes for a Kubernetes cluster on Openstack using Pulumi.
Note: By default, the values in the Pulumi.yaml
use Infomaniak Openstack. You can change the values in the Pulumi.yaml
file to match your Openstack configuration.
- Install Pulumi
- Install Python3
- Create a virtual environment:
python3 -m venv venv
- Install the required Python packages:
python3 -m pip install -r requirements.txt
Login to your openstack account (horizon) and source the openstack rc file:
source openstack.rc
Create a new project using this template:
pulumi new https://github.com/qjoly/pulumi-kubernetes-openstack/tree/main
Run the pulumi program:
pulumi up
Export the private key that can be used to connect to the nodes:
pulumi stack output nodes_keypair --show-secrets > nodes_keypair.pem
Send it to the admin node:
scp nodes_keypair.pem debian@$(pulumi stack output admin_external_ip):.ssh/id_rsa
ssh debian@$(pulumi stack output admin_external_ip) chmod 600 .ssh/id_rsa
Generate the inventory file:
pulumi stack output ip_addresses --json | python3 generate_inventory.py > inventory.ini
scp inventory.ini debian@$(pulumi stack output admin_external_ip):./inventory.ini
On the admin node, Create a virtual environment and install the required packages:
ssh debian@$(pulumi stack output admin_external_ip)
git clone https://github.com/kubernetes-sigs/kubespray && cd kubespray
cp -r inventory/sample/ ./inventory/pulumi-cluster
cp ~/inventory.ini ./inventory/pulumi-cluster/inventory.ini
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
ansible-playbook -i ./inventory/pulumi-cluster/inventory.ini -u debian --become --become-user=root cluster.yml
All in one script
pulumi stack output nodes_keypair --show-secrets > nodes_keypair.pem
scp nodes_keypair.pem debian@$(pulumi stack output admin_external_ip):.ssh/id_rsa
ssh debian@$(pulumi stack output admin_external_ip) chmod 600 .ssh/id_rsa
pulumi stack output ip_addresses --json | python3 generate_inventory.py > inventory.ini
scp inventory.ini debian@$(pulumi stack output admin_external_ip):./inventory.ini
ssh debian@$(pulumi stack output admin_external_ip) \ '
git clone https://github.com/kubernetes-sigs/kubespray && cd kubespray && \
cp -r inventory/sample/ ./inventory/pulumi-cluster && \
cp ~/inventory.ini ./inventory/pulumi-cluster/inventory.ini && \
python3 -m venv venv && \
source venv/bin/activate && \
pip install -r requirements.txt && \
ansible-playbook -i ./inventory/pulumi-cluster/inventory.ini -u debian --become --become-user=root cluster.yml'
CP_IP=$(pulumi stack output 'ip_addresses' | jq -r '."kube-controlplane"[0]')
ssh debian@$(pulumi stack output admin_external_ip) "ssh-keyscan -H $CP_IP >> ~/.ssh/known_hosts && mkdir -p .kube && ssh $CP_IP sudo cat /root/.kube/config > .kube/config && sed -i 's/127.0.0.1/$CP_IP/g' ~/.kube/config && chmod 600 .kube/config && echo 'Done'"
To destroy the resources created by the Pulumi program, run the following command:
pulumi destroy