From 91d2615e2a4750c84c0075c89a9941e5b68ca17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Kopi=C4=87?= Date: Sat, 13 Apr 2024 18:14:56 +0000 Subject: [PATCH] Update Kubernetes --- Kubernetes.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/Kubernetes.md b/Kubernetes.md index df54ca2..002afdd 100644 --- a/Kubernetes.md +++ b/Kubernetes.md @@ -44,6 +44,19 @@ MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.4/config/manifests/metallb-native.yaml ``` +## Accessing the cluster from your machine + +Kubernetes config file can be found on any of the control plane nodes at: +``` +/etc/rancher/k3s/k3s.yaml +``` + +You can copy that file over to your PC to +``` +~/.kube/config +``` +And edit the server url from 127.0.0.1 to the ip addres of one of the control plane nodes + ### MetalLB IP pool Create a new yaml file with the following content and be sure to customize your ip range: ``` @@ -211,3 +224,74 @@ then apply it: ``` kubectl apply -f file.yml ``` + +# Kubernetes Dashboard + +I you want to be extra fancy you can deploy a web UI Dashboard for your kubernetes. +You need HELM for this one +``` +helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/ +helm repo update +``` + +Fetch the default values file: +``` +helm show values kubernetes-dashboard/kubernetes-dashboard > values.yaml +``` + +Edit it and enable ingress: +``` + ingress: + enabled: true + hosts: + - dash..my.cluster.com + ingressClassName: nginx +``` + +And install it with the modified values file: +``` + helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard --values values.yaml +``` + +## Create service account for accesing the dashboard as admin + +Create a service account file +``` +apiVersion: v1 +kind: ServiceAccount +metadata: + name: myusername + namespace: kubernetes-dashboard +``` +then apply it: +``` +kubectl apply -f file.yml +``` + + +Then create a file to bind your user to the built in cluster-admin role + +``` +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: myusername +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: +- kind: ServiceAccount + name: myusername + namespace: kubernetes-dashboard +``` +then apply it: +``` +kubectl apply -f file.yml +``` + + +And finally, create a token you can use to login to the dashboard +``` +kubectl -n kubernetes-dashboard create token myusername +``` \ No newline at end of file