Bekir KUCUKALA
8 min readJun 29, 2021

--

Installing MicroK8S On AWS on Ubuntu20.04 server

MicroK8s is the smallest, fastest, fully-conformant Kubernetes that tracks upstream releases and makes clustering trivial. MicroK8s is great for offline development, prototyping, and testing. Use it on a VM as a small, cheap, reliable k8s for CI/CD. It’s also the best production grade Kubernetes for appliances. Develop IoT apps for k8s and deploy them to MicroK8s on your Linux boxes.

MicroK8s automatically chooses the best nodes for the Kubernetes datastore. When you lose a cluster database node, another node is promoted. No admin needed for your bulletproof edge

Before installing Microk8S we have to start Ubuntu Server 20.04. We click “launch instance” at EC2 dashboard.

  • Kubernetes need minimum 2CPU and 2 GB Ram. Because of that we select t3a.medium. Then click Next.
  • On demand Prices are nearly 4 times expensive then Spot Prices. So we can install a Spot instance with low price. Click “Request Spot Instances”. Its optional but you may write maximum price. We use“onetime” spot instance. You don’t have to select ‘Persistent request’
  • I select storage size 25 GB, but 8Gb storage size is enough. Click next.

- Add these ports to the security group.

|Protocol |Direction| Port Range |Purpose |Used By|

|TCP|Inbound|80|Http|All|

|TCP|Inbound|443|Https|All|

|TCP|Inbound|6443|Kubernetes API server|All|

|TCP|Inbound|2379–2380|`etcd` server client API|kube-apiserver, etcd|

|TCP|Inbound|10250|Kubelet API|Self, Control plane|

|TCP|Inbound|10251|kube-scheduler|Self|

|TCP|Inbound|10252|kube-controller-manager|Self|

|TCP|Inbound|22|remote access with ssh|Self|

|UDP|Inbound|8472|Cluster-Wide Network Comm. — Flannel VXLAN|Self|

|TCP|Inbound|30000–32767|NodePort Services†|All|

  • All configuration is ready. It alerts that this is not free usage tier. Please click next.
  • Don’t forget to select key pair to connect to instance.
  • Go to the instance select ‘instance ’ and please click to connect to get ssh connection command
  • Copy the connection command
  • Write “yes” and push enter to continue. Now we connected our ubuntu20.04 instance. We will install microK8S to our instance.
  • Please update the instance with “sudo apt-get update -y && sudo apt-get upgrade –y”.

- Now we updated our instance and we are ready to install MicroK8S. Please write this command. İt will take some minutes.

  • ‘ sudo snap install microk8s –classic ‘

We installed MicroK8S. It comes with add-ons. To be as lightweight as possible, MicroK8s only installs the basics of a usable
Kubernetes install:

  • api-server
  • controller-manager
  • scheduler
  • kubelet
  • cni
  • kube-proxy

While this does deliver a pure Kubernetes experience with the smallest of
resource footprints, there are situations where you may require additional
services. MicroK8s caters for this with the concept of “Addons” — extra
services which can easily be added to MicroK8s. These addons can be enabled
and disabled at any time, and most are pre-configured to ‘just work’ without
any further set up. Current MicroK8s Addons are;

  • ambassador: (1.19+ tracks) Ambassador is an API and Ingress controller.
  • dashboard: The standard Kubernetes Dashboard.
  • dns: Deploys CoreDNS. This add-on may be required by others — it is recommended you always enable it. In restricted environments you may need to update the upstream DNS servers.
  • cilium: Deploys Cilium to support Kubernetes network policies using eBPF.
  • fluentd: Deploy the Elasticsearch-Fluentd-Kibana logging and monitoring solution.
  • gpu: Enable support for GPU accelerated workloads using the NVIDIA runtime.
  • helm: Installs the Helm 2 package manager for Kubernetes.
  • helm3: Installs the Helm 3 package manager for Kubernetes.
  • host-access: Provides a fixed IP for access to the host’s services.
  • ingress: A simple ingress controller for external access.
  • istio: Adds the core Istio services (not available on arm64 arch).
  • jaeger: Deploy the Jaeger Operator in the “simplest” configuration.
  • juju: Enables a juju client to work with MicroK8s.
  • keda: (1.20+ tracks) Deploys KEDA — Kubernetes Event-driven Autoscaling operator.
  • knative: Adds the Knative middleware to your cluster (not available on arm64 arch).
  • kubeflow: Adds Kubeflow using the Charmed Kubeflow operators.
  • linkerd: Deploys the linkerd service mesh ( arm64 version available in 1.20+).
  • metallb: Deploys the MetalLB Loadbalancer. Note that currently this does not work on macOS, due to filtering that macOS applies to network traffic.
  • metrics-server: Adds the Kubernetes Metrics Server for API access to service metrics.
  • multus: (1.19+ tracks) Add multus for multiple network capability.
  • openfaas: OpenFaaS, the popular serverless framework, (not available on arm64 arch).
  • openebs: Add OpenEBS storage capability, (not available on arm64 arch).
  • portainer: Container management dashboard (see portainer.io).
  • prometheus: Deploys the Prometheus Operator.
  • rbac: Enable Role Based Access Control for authorisation. Note that this is incompatible with some other add-ons.
  • registry: Deploy a private image registry and expose it on localhost:32000. The storage add-on will be enabled as part of this add-on. See the registry documentation for more details.
  • storage: Create a default storage class which allocates storage from a host directory. N.B. This is simple filesystem storage local to the node where it was added — you may require something more complex for a cluster.
  • traefik: (1.20+ tracks) Adds the Traefik Kubernetes Ingress controller.

We will install add-ons dashboard, dns, registry ,istio “microk8s enable dashboard dns registry istio”. We run but it fails because of insufficient permissions. To run command ‘kubectl’ without sudo command we will run these commands.

sudo usermod -a -G microk8s ubuntu
sudo chown -f -R ubuntu ~/.kube
  • The new group will be available on the next login. So that we type ‘exit’ to logout and then login again.

We can install add-ons.

microk8s enable dashboard dns registry istio
  • We uses alias to write shorter
sudo snap alias microk8s.kubectl kubectl
  • Now we can see every thing with the below command. We defined alias so that we can use both.
microk8s kubectl get all - all-namespaces 
kubectl get all - all-namespaces
  • To Access to the MicroK8S dashboard from public IP that we have to edit config file.
kubectl -n kube-system edit service kubernetes-dashboard
  • NOTE: This command open the configuration yaml file by vi editör. Press “i” to make changes in insert mode.
  • After changing ‘ClusterIP’ to ‘NodePort’, press ‘:’ and write ‘wq!’ to save and exit.
  • Let’s see the services.
Kubectl -n kube-system get services -o wide

- Now we are ready to connect to MicroK8S from Browser. First we have to learn EC2 public address.

  • Go to the EC2 service at AWS Console.
  • You can see the public IP address. Please copy this address
  • Please run this commands to get token and please copy this token.
kubectl get secrets
kubectl describe secrets/default-token-tmvz7
  • Please copy token and paste it in login screen
  • MicroK8S looks like that. We can see configuration.

- Then lets a deploy something and see what happens.

  • On the command line create a mydeployment.yaml file. ‘nano mydeployment.yaml’
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
environment: dev
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
  • Create the deployment with `kubectl apply` command.
kubectl apply -f mydeployment.yaml
  • List the deployments, pods, replicasets with more information
kubectl get deploy,pods,rs -o wide
  • Let’s see them dashboard interfaces.

Please don’t forget to cancel the Spot requests from EC2 dashboard. Please open Spot Requests

  • Then select our spot request and from actions menu click ‘Cancel Request ’

- Please apply ‘confirm’ to cancel spot request and terminate the instances.

If you liked this post, please recommend it and share it with your followers.

REFERENCES:

https://docs.aws.amazon.com/ec2/index.html?nc2=h_ql_doc_ec2

--

--