GithubHelp home page GithubHelp logo

5l1v3r1 / k8s-lab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from serain/k8s-lab

0.0 1.0 0.0 26 KB

Self-managed Kubernetes from scratch on Azure - with Terraform and Ansible

Makefile 6.86% HCL 93.14%

k8s-lab's Introduction

Kubernetes Lab

Self-managed Kubernetes from scratch on Azure, with Terraform and Ansible

Acknowledgements

This is heavily based on Kelsey Hightower's Kubernetes the Hard Way for GCP.

His cluster was transliterated to Azure and automated with Terraform and Ansible. Additional changes include isolating controllers and workers into distinct subnets to enforce stricter network access controls, and tweaking some of the networking decisions to theoretically scale up to 250 controllers and workers.

Motivation and Purpose

Managed clusters from cloud providers abstract most of the underlying Kubernetes components away, and desktop-focussed solutions like Minikube are not representative of production clusters.

This was built to:

  • understand how Kubernetes components fit together, from the ground up
  • provide a representative playground to fiddle around with custom security scenarios, such as those that may be encountered during pentests

Quick Use

Create an Azure service principal account for Terraform, copy tf/environment/secrets.tfvars.sample to tf/environment/secrets.tfvars, and populate the file with your service principal details and SSH public key:

# tf/environment/secrets.tfvars
subscription_id         = ""
client_id               = ""
client_secret           = ""
tenant_id               = ""

vm_ssh_key = ""

The project uses a Makefile to call Terraform and then Ansible:

$ make
...
================================================================================

The Kubernetes endpoint is: https://40.81.58.6:6443/

CA cert is in: as/certs/ca/ca.pem

Admin user cert and key are in: as/certs/admin/admin(-key).pem

kubectl has been configured for the cluster

SSH:
  ssh -F as/ssh_config jumpbox
  ssh -F as/ssh_config k8s-controller-vm-0
  ssh -F as/ssh_config k8s-worker-vm-0

================================================================================

Configuration

The tf/environment/env.tfvars contains most of the configurable details, including number of controllers and workers and respective VM sizes.

Security

This cluster implements some good security practices:

  • mutual TLS authentiction between all components
  • etcd secrets encrypted at rest
  • support for gVisor for untrusted payloads

Caution: during setup some binaries are pulled from remote URLs without integrity checks, theoretically opening the installation to supply-chain attacks

That being said, this cluster isn't hardened and was built with training in mind. I do not recommend it for production use.

Limitations and Known Issues

The Ansible is not idempotent; everytime you run it, new certs will be generated and services will bounce.

There's an apparent bug with NSG-subnet associations in the azurerm Terraform provider that causes NSG's to disassociate from subnets when updating a terraformed environment. You'll run into this issue is you try to rebuild/update an existing cluster. ATM you'll need to re-attach the NSGs to the subnets from the CLI or portal, or build from scratch.

k8s-lab's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.