dozman99 / cloudkube-aks-clusters

3 Clusters, 1 Repo. Opinionated infrastructure as code for my Azure Kubernetes clusters for running demo apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cloudkube.io - AKS Clusters

An opinionated Azure Kubernetes Service (AKS) cluster for running demo apps, leveraging Makefile instead of lots of bash-fu to install AKS add-ons.

Table of Contents

Architecture

The following diagram illustrates the Azure solution architecture for each cluster, e.g. dev, staging and prod.

Cloudkube.io AKS Cluster

Architecture Decisions

Networking

Identity & Security

Miscellaneous

  • Prefer -managed-rg suffix over default MC_ prefix for resource group containing managed cluster

Managed Identities - Control Plane vs Kubelet

Managed Identity Security Principal Details
control-plane-mi AKS Control Plane Interfaces with ARM to manage cluster resources, VMs, networking, etc.
kubelet-mi K8s Node Agent Needs some access e.g. Container Registry and Key Vault to setup workloads.

Environments

Resources names will include one of

  • dev
  • staging
  • prod (currently not used)

Hosts

Setup and Configure

Using Terraform and make commands, you will have an AKS cluster with all the Azure CSI and Pod Identity Add-Ons up and running with just 5 commands.

1) Requirements

CLI Tools (Required)

In order to deploy AKS clusters using IaC in this repository, you will need the following command line tools:

Shared Infrastructure (Required)

The following Azure resources are located in a separate Resource Group cloudkube-shared-rg and managed by the cloudkube-shared-infra repository:

  • DNS Records
  • Key Vaults
  • Role Assignments to access TLS Certificates

Without these resources, the setup of the Ingress controller will fail as it wants to configure TLS encryption.

Storage Accounts for Terraform State Files (Optional)

This is not necessary if you just want to deploy and manage a single cluster from your local machine. In cloudkube.io use case, this infrastructure as code (IaC) repo is used to manage 3 distinct AKS clusters and will be integrated with CI/CD.

And to comply with governance best practices, we have 2 different storage accounts to create a security boundary between production and non-production resources.

Use different Storage Accounts for RBAC on Terraform State

Diagram: use different Storage Accounts for RBAC on Terraform State. See backends/README.md for details.

2) Deploy AKS Cluster

terraform init

First initialize the remote backend and specify which environment, e.g. backends/dev.backend.hcl

terraform init -backend-config=backends/dev.backend.hcl

If you dont' want to deal with remote and multiple environments, you can leave out the -backend-config flag.

terraform plan

Now create a infrastructure plan. Specify environment configuration with var-file flag pointing to e.g. environments/dev.tfvars

terraform plan -var-file=environments/dev.tfvars -out plan.tfplan

terraform apply

If you are satisified with the plan, deploy it

terraform apply plan.tfplan

3) Re-configure Shared Infra

If the cluster is a re-created, go to julie-ng/cloudkube-shared-infra and run the infra as code there to

  • update DNS records to new Static IP
  • update RBAC Assignments to Key Vault that holds TLS certificates. Otherwise ingress controller deployment will fail.

When that runs, come back here.

4) Setup Ingress

Finally finish cluster setup with

make kubecontext
make setup

which will

  • install Azure CSI driver
  • setup namespaces
  • install nginx ingress controller
  • setup and configure "hello world" app
  • configure TLS by pull certificates from shared Key Vault

See Makefile for details.

Cluster Upgrades

If an upgrade (e.g. enable Azure RBAC) requires Terraform to destroy and re-create the cluster, then additional steps are required after terraform apply

  • re-setup with make setup was required
  • re-setup access to TLS certificates for ingress
    • the managed identities for kubelet and ingress change, which requires re-deploying cloudkube-shared-infra.
    • then finish setup by re-running failed step make apply-hello

Miscellaneous

Update Change log

To update CHANGELOG.md with standard-version run

standard-version --packageFiles manifest.json --sign --release-as minor

then adjust as needed by hand and commit.

References

Official Documentation

Terraform

Azure

Nginx Ingress Controller

About

3 Clusters, 1 Repo. Opinionated infrastructure as code for my Azure Kubernetes clusters for running demo apps.

License:MIT License


Languages

Language:HCL 78.9%Language:Makefile 21.1%