Klikk.com offers a sovereign IaaS platform with a developer-centric API, enabling programmatic control over virtual instances. This flexibility allows SaaS providers to automate infrastructure provisioning and management, ensuring scalability and compliance.

Step 1: Automate VM Provisioning with Ansible

Utilize Ansible to interact with Klikk.com’s API for creating virtual machines.

Example: Provisioning a VM Using Ansible

- name: Provision VM on Klikk.com
  hosts: localhost
  gather_facts: no
  tasks:
    - name: Create a new virtual machine
      uri:
        url: "https://my.klikk.com/api/v1/instances"
        method: POST
        headers:
          Authorization: "Bearer {{ klikk_api_token }}"
          Content-Type: "application/json"
        body: |
          {
            "name": "app-server-01",
            "image": "ubuntu-22.04",
            "flavor": "medium",
            "network": "public"
          }
        body_format: json
        return_content: yes
      register: create_vm_response

    - name: Display VM creation response
      debug:
        var: create_vm_response.json

Replace {{ klikk_api_token }} with your actual API token. This playbook sends a POST request to Klikk.com’s API to create a new virtual machine with specified parameters.

Step 2: Deploy Kubernetes on the Provisioned VM

After provisioning the VM, install Kubernetes to manage your SaaS applications.

Example: Installing k3s on the VM

- name: Install k3s on Klikk VM
  hosts: app-server-01
  become: yes
  tasks:
    - name: Install k3s
      shell: |
        curl -sfL https://get.k3s.io | sh -
      args:
        creates: /usr/local/bin/k3s

    - name: Retrieve kubeconfig
      shell: cat /etc/rancher/k3s/k3s.yaml
      register: kubeconfig_content

    - name: Save kubeconfig locally
      copy:
        content: "{{ kubeconfig_content.stdout }}"
        dest: "./kubeconfig"

This playbook installs k3s, a lightweight Kubernetes distribution, and retrieves the kubeconfig file for cluster management.

Step 3: Deploy Your SaaS Application

With Kubernetes set up, deploy your SaaS application using standard Kubernetes manifests.

Example: Deploying an Application

apiVersion: apps/v1
kind: Deployment
metadata:
  name: saas-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: saas-app
  template:
    metadata:
      labels:
        app: saas-app
    spec:
      containers:
      - name: saas-container
        image: your-registry/saas-app:latest
        ports:
        - containerPort: 8080

Apply the deployment using:

kubectl --kubeconfig=./kubeconfig apply -f saas-deployment.yaml

Optional: Enable Auto-Scaling

Implement Kubernetes Horizontal Pod Autoscaler (HPA) to scale your application based on demand.

kubectl --kubeconfig=./kubeconfig autoscale deployment saas-app --cpu-percent=50 --min=3 --max=10

Summary

By integrating Ansible and Kubernetes with Klikk.com’s API, you can:

  • Automate infrastructure provisioning
  • Deploy scalable SaaS applications
  • Maintain data sovereignty within Norway

For further assistance or to access starter templates, feel free to contact our support team.