Last active
December 14, 2022 12:04
-
-
Save bergpb/51b3b69f62c02e23bf6c618b29d3bf09 to your computer and use it in GitHub Desktop.
Revisions
-
bergpb revised this gist
Dec 14, 2022 . No changes.There are no files selected for viewing
-
bergpb revised this gist
Dec 14, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -121,5 +121,5 @@ Install k3s + MetalLB in a cluster with RaspberryPi. Useful links related to MetalLB configurations: [Reload IP configuration](https://github.com/metallb/metallb/issues/348) [IP Range change workflow](https://github.com/metallb/metallb/issues/308) -
bergpb revised this gist
Dec 14, 2022 . 1 changed file with 15 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,10 +23,12 @@ Install k3s + MetalLB in a cluster with RaspberryPi. ```kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml``` 1. The followed commands need to be executed in Control Node. 1. Define the IP addresses that will be used by MetalLB, we need to create a config.yml file and apply with kubectl: ```touch config.yml``` ``` apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: @@ -41,6 +43,7 @@ Install k3s + MetalLB in a cluster with RaspberryPi. 1. To testing these configurations, let's deploy the a Nginx in the cluster: ```touch deployment.yml``` ```yml apiVersion: apps/v1 kind: Deployment @@ -62,7 +65,9 @@ Install k3s + MetalLB in a cluster with RaspberryPi. ports: - containerPort: 80 ``` ```touch service.yml``` ```yml apiVersion: v1 kind: Service @@ -85,7 +90,7 @@ Install k3s + MetalLB in a cluster with RaspberryPi. ```kubectl get pods``` ```kubectl get services``` 1. The output will be similar to this one: ```bash pi@raspberrypi:~/k8s-nginx $ kubectl get pods @@ -101,9 +106,9 @@ Install k3s + MetalLB in a cluster with RaspberryPi. nginx LoadBalancer 10.43.134.193 10.0.0.10 80:30341/TCP 19h ``` 1. The nginx service will be avaliable on External IP 10.0.0.10, to access in your browser. 1. If you need to remove the k3s installation just run the followed commands: 1. Control Plane: @@ -112,3 +117,9 @@ Install k3s + MetalLB in a cluster with RaspberryPi. 2. Workers: ```/usr/local/bin/k3s-agent-uninstall.sh``` Useful links related to MetalLB configurations: [Reload IP configuration](https://github.com/metallb/metallb/issues/348) [IP Range change workflow](https://github.com/metallb/metallb/issues/308) -
bergpb revised this gist
Dec 14, 2022 . 1 changed file with 106 additions and 80 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,88 +1,114 @@ ## K3S + MetalLB Install k3s + MetalLB in a cluster with RaspberryPi. #### Instructions: 1. Edit `/boot/cmdline.txt` file and the configuration at the end of line: `cgroup_memory=1 cgroup_enable=memory` 1. On control node, generate a secret and install k3s: ```TOKEN=`python3 -c "import secrets; print(secrets.token_hex(32))"` ``` ```curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644 --disable servicelb --token $TOKEN --bind-address <control_node_ip>``` 1. Run the followed command in worker nodes: ```curl -sfL https://get.k3s.io | K3S_URL=https://<control_node_ip>:6443 K3S_TOKEN=<token> sh -``` 1. When the installation is completed, let's relabel the worker nodes: ```kubectl label nodes <node_name> kubernetes.io/role=worker``` 1. Now, connect throught ssh with control node and install MetalLB: ```kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml``` 1. Define the IP addresses that will be used by MetalLB, we need to create a config.yml file and apply with kubectl: ```touch config.yml``` ```yml apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: name: config namespace: metallb-system spec: addresses: - <first_node_ip_in_cluster>-<last_node_ip_in_cluster> ``` ```kubectl apply -f config.yml``` 1. To testing these configurations, let's deploy the a Nginx in the cluster: ```touch deployment.yml``` ```yml apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: selector: matchLabels: app: nginx replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:alpine ports: - containerPort: 80 ``` ```touch service.yml``` ```yml apiVersion: v1 kind: Service metadata: name: nginx spec: selector: app: nginx ports: - port: 80 targetPort: 80 type: LoadBalancer ``` ```kubectl apply -f deployment.yml``` ```kubectl apply -f service.yml``` 1. To check if the the deployment and services are running as expected, run the followed commands: ```kubectl get pods``` ```kubectl get services``` 10. The output will be similar to this one: ```bash pi@raspberrypi:~/k8s-nginx $ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-965685897-bddf7 1/1 Running 0 19h nginx-965685897-cfx4z 1/1 Running 0 19h nginx-965685897-n274m 1/1 Running 0 19h nginx-965685897-wxblb 1/1 Running 0 19h nginx-965685897-t2zhr 1/1 Running 0 19h pi@raspberrypi:~/k8s-nginx $ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 19h nginx LoadBalancer 10.43.134.193 10.0.0.10 80:30341/TCP 19h ``` 11. The nginx service will be avaliable on External IP 10.0.0.10, to access in your browser. 12. If you need to remove the k3s installation just run the followed commands: 1. Control Plane: ```/usr/local/bin/k3s-uninstall.sh``` 2. Workers: ```/usr/local/bin/k3s-agent-uninstall.sh``` -
bergpb created this gist
Dec 13, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,88 @@ all nodes: [INFO] Failed to find memory cgroup, you may need to add "cgroup_memory=1 cgroup_enable=memory" to your linux cmdline (/boot/cmdline.txt on a Raspberry Pi) control node: python3 -c "import secrets; print(secrets.token_hex(32))" curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644 --disable servicelb --token c50e74c7dab0703961c16e10a23b89867ad20b5f6f1472b2be889184b08cbee2 --bind-address 10.0.0.10 run in worker nodes: curl -sfL https://get.k3s.io | K3S_URL=https://10.0.0.10:6443 K3S_TOKEN=c50e74c7dab0703961c16e10a23b89867ad20b5f6f1472b2be889184b08cbee2 sh - label nodes in kbectl output: kubectl label nodes <node_name> kubernetes.io/role=worker install metallb: kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml creating and applying a configmap for metallb: touch configmap.yml content: apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: name: config namespace: metallb-system spec: addresses: - 10.0.0.10-10.0.0.12 kubectl apply -f configmap.yml if i need to change the configmap: https://github.com/metallb/metallb/issues/308 creating a deployment: touch deployment.yml content: apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: selector: matchLabels: app: nginx replicas: 5 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:alpine ports: - containerPort: 80 kubectl apply -f deployment.yml creating a service: touch service.yml content: apiVersion: v1 kind: Service metadata: name: nginx spec: selector: app: nginx ports: - port: 80 targetPort: 80 type: LoadBalancer kubectl apply -f service.yml get information: kubectl get all uninstall in main: /usr/local/bin/k3s-uninstall.sh uninstall in worker: /usr/local/bin/k3s-agent-uninstall.sh