summaryrefslogtreecommitdiff
path: root/src/content/post/deploy-kubernetes-cluster-in-minutes-with-k3s.md
blob: 2d02c4b2eb1d07509df56a0638be6d7406395594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
title: "Deploy K8s Cluster in Minutes with k3s"
description: "deploy kubernetes cluster in minutes with k3s with metallb letsencrypt nginx ingress"
publishDate: "2020-03-23"
tags: ["archived", "docker", "kubernetes", "en"]
author: "Dawid"
---

[K3S](https://k3s.io) is a lightweight and certified Kubernetes distribution, perfect for run development environments, CI/CD and IoT. It works very well with the ARM architecture. It's packaged to a single binary that makes deployment and setup easy.

The default installation comes with:

- embedded SQLite
- containerd
- flannel
- coredns
- traefik (ingress controller)
- local path provisioner
- service load balancer

All those features are more than enough for most use-cases. Of course, installation is fully configurable, so if you want etcd, docker, Nginx ingress and so on - go to official documentation page https://rancher.com/docs/k3s/latest/en/ .

## Default installation

Login to machine and run:

```bash
curl -sfL https://get.k3s.io | sh -
```

and that's it...
After a few seconds, you should see that the master node is ready with `k3s kubectl get node`.

You will find *config.yaml* for kubernetes in `/etc/rancher/k3s/k3s.yaml`

## Advanced installation with nginx-ingress, metallb and cert-manager

1. Deploy k3s without traefik and servicelb

    ```bash
    curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC=" --no-deploy=servicelb --no-deploy=traefik" sh -s -
    ```

2. Get config from `/etc/rancher/k3s/k3s.yaml` and put into `~/.kube/config` on your machine

3. [Install helm](https://helm.sh/docs/intro/install/)

    ```bash
    curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
    ```

4. Add helm repo and update

    ```bash
    helm repo add stable https://kubernetes-charts.storage.googleapis.com/
    helm repo update
    ```

5. Install [metallb](https://github.com/metallb/metallb). Range of available ip addresses for loadbalancer are set in `configInline.address-pools[0].addresses[0]`.

    ```bash
    helm install --namespace=kube-system \
      --set configInline.address-pools[0].name=default \
      --set configInline.address-pools[0].protocol=layer2 \
      --set configInline.address-pools[0].addresses[0]=192.168.1.10-192.168.1.50 \
      metallb stable/metallb
    ```

6. Install [nginx-ingress](https://github.com/kubernetes/ingress-nginx)

    ```bash
    helm install --namespace=kube-system \
        --set rbac.create=true \
        nginx-ingress stable/nginx-ingress
    ```

7. Install and configure [certmanager](https://github.com/jetstack/cert-manager) for lets-encrypt

    ```bash
    kubectl apply -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.14/deploy/manifests/00-crds.yaml

    helm install --namespace=kube-system cert-manager stable/cert-manager

    cat <<EOF | kubectl apply -f -
    apiVersion: cert-manager.io/v1alpha2
    kind: ClusterIssuer
    metadata:
      name: letsencrypt
    spec:
      acme:
        server: https://acme-v02.api.letsencrypt.org/directory
        email: ACME_EMAIL
        privateKeySecretRef:
          name: letsencrypt
        solvers:
          - dns01:
              cloudflare:
                email: CLOUDFLARE_EMAIL
                apiKeySecretRef:
                  name: cloudflare-apikey-secret
                  key: CLOUDFLARE_APIKEY
            selector:
              dnsNames:
                - 'DOMAIN_NAME'
    EOF
    ```

    Where:
      - **ACME_EMAIL** - some email in yor domain (will be used to limit number of requests to acme)
      - **CLOUDFLARE_EMAIL** - email of your cloudflare account
      - **CLOUDFLARE_APIKEY** - api key to your cloudflare account
      - **DOMAIN_NAME** - domain that will be used in lets-encrypt certs (eg.: `*.rycerz.co`)

## Important disclaimer

Don't deploy everything in kube-system if it's not test/development cluster. Be safe.