Coder Social home page Coder Social logo

mathieu-benoit / myakscluster Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 10.0 544 KB

How to setup a secure Kubernetes cluster on Azure

Home Page: http://alwaysupalwayson.com/private-aks-and-acr/

Shell 33.45% HCL 66.55%
devops k8s kubernetes azure aks kured azure-monitor security cloud-security terraform

myakscluster's Introduction

Build Status

myakscluster

Here are blog articles related to this repository:

To properly setup and secure your AKS cluster, there is a couple of features and components to enable in order to properly setup your Security Posture, here is the list:

Basic - without cost:

  • Managed Identity #62
  • Azure Lock #21
  • kured #13
  • Disable K8S Dashboard #24
  • Network Policy with Calico #9
  • AAD #10
  • Azure Policy for AKS #11
  • Azure KeyVault for Azure pipelines #3

Advanced - with cost:

Complementary Azure services to leverage:

  • Azure Advisor for AKS
  • Azure Security Center for ACR
  • Azure Security Center for AKS

Architecture diagram

Provisioning

Prerequisites

  • Install Azure CLI
  • Install Terraform
    • Optional if you would like to leverage Terraform instead of Azure CLI.
  • Install Azure ConnectedK8s and KubernetesConfiguration CLI extensions
    • Optional if you would like to use Azure Arc enabled Kubernetes.

Configuration pre-provisioning

az login
#az account list -o table
#az account set -s <subscriptionId>

export LOCATION='canadacentral'
export NODES_COUNT=3
export NODE_SIZE='Standard_DS2_v2'
export ZONES=false

./run-pre-checks.sh

randomSuffix=$(shuf -i 1000-9999 -n 1)
export AKS=FIXME$randomSuffix
export K8S_VERSION=$(az aks get-versions \
  -l $LOCATION \
  --query "orchestrators[?isPreview==null].orchestratorVersion | [-1]" \
  -o tsv)

Provisioning Option 1: Azure CLI

cd cli
./create-aks-cluster.sh

FYI, current issues/workarounds with Azure CLI:

Provisioning Option 2: Terraform

cd tf
sudo terraform init
terraform plan \
  -var aks_name=$AKS \
  -var k8s_version=$K8S_VERSION \
  -var location=$LOCATION \
  -var aks_node_count=$NODES_COUNT \
  -var aks_node_size=$NODE_SIZE
terraform apply \
  -auto-approve \
  -var aks_name=$AKS \
  -var k8s_version=$K8S_VERSION \
  -var location=$LOCATION \
  -var aks_node_count=$NODES_COUNT \
  -var aks_node_size=$NODE_SIZE

Configuration post-provisioning

You need to connect to the Jumpbox VM via the Bastion host and run the commands below:

az login \
  --service-principal \
  -u FIXME \
  -p FIXME \
  --tenant-id FIXME
az aks get-credentials \
  -g $RG \
  -n $RG
./configure-aks-cluster.sh

Pricing estimation

  • AKS
    • $0.10 per cluster per hour.
  • Virtual Machines related to AKS worker nodes
    • Estimation: For 2 Node pools X 3 Standard_DS2_v2 Ubuntu worker nodes, ~ $xx USD/month
    • To decrease the cost: you may want to leverage Azure Reserved VMs Instances to reduce the cost of your AKS worker nodes
  • Managed Disks (related to the AKS's Nodes OS Disk)
    • Estimation: ~ $xx USD/month
  • Log Analytics Workspace (related to the Azure Monitor for Containers add-on)
  • Standard Load Balancer
    • Estimation: TODO
    • To decrease the cost: you may want to leverage Basic Load Balancer instead which is free but you won't be able to use Availability Zones nor VNET Peering features
  • Azure Firewall
    • Estimation: TODO
  • Public IP
    • Related to the SLB + FW
    • Estimation: TODO
  • Bandwidth (related to Availability Zones)
    • Estimation: TODO
    • Note: you may want to leverage PodAffinity to avoid cross-zones communications with Pods too chatty
  • Private Endpoint
    • Estimation: For 2 Private Endpoints (AKS + ACR)
  • Bastion - TODO

Other considerations:

Resources

myakscluster's People

Contributors

mathieu-benoit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

myakscluster's Issues

Use --network-policy in az aks create to leverage Calico

Standard Load Balancer

Some gotchas:

  • The load-balancer-sku property can only be used when your cluster is created. You cannot change the load balancer SKU after an AKS cluster has been created. Also, you can only use one type of load balancer SKU in a single cluster.
  • If you want to use your own public IPs, use the load-balancer-outbound-ips, or load-balancer-outbound-ip-prefixes parameters. Both of these parameters can also be used when updating the cluster.
  • VNET Peering is now possible with SLB, it was not with Basic Load Balancer
  • SLB is required for Availability Zones #33

(Beta) Helm 3

Availability Zones

Managed Identity

Leveraging Managed Identity with AKS instead of Service Principal is more secure for 2 main reasons:

  • There is not anymore the credentials file stored on any AKS nodes (/host/etc/kubernetes/azure.json)
  • MI will wrap and managed the credentials (auto-rotate, when expired, etc.) for you

(Preview) Pod Security Policy

AAD integration

Use IP whitelisting for the Kubernetes API

Prerequisities:

  • Only with Standard Load Balancer
  • Implementation with kubenet CNI otherwise with Azure CNI route table will have to be created manually like explained in the doc
  • Min Azure CLI version: 2.0.76

Multiple Node Pools

Learnings and Gotchas:

  • First Node Pool at cluster creation is Linux
  • We can't delete the first Node Pool
  • HTTP application routing add-on can't be used
  • Linux node pools the length must be between 1-12 characters, for Windows node pools the length must be between 1-6 characters
  • Maximum of eight node pools
  • Maximum of 400 nodes across those 8 node pools
  • All node pools must reside in the same subnet (Azure/azure-cli#10984)
  • Must use virtual machine scale sets for the nodes
  • When upgrading a cluster the new nodes will get the taints
  • When you scale a node pool in AKS, taints and tolerations do not carry over by design (Azure/AKS#1061)

Taints and tolerations are used to logically isolate resources with a hard cut-off - if the pod doesn't tolerate a node's taint, it isn't scheduled on the node. An alternate approach is to use node selectors. You label nodes, such as to indicate locally attached SSD storage or a large amount of memory, and then define in the pod specification a node selector. Kubernetes then schedules those pods on a matching node. Unlike tolerations, pods without a matching node selector can be scheduled on labeled nodes. This behavior allows unused resources on the nodes to consume, but gives priority to pods that define the matching node selector.

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.