kubernetes-kubernetes-installing-a-local-cluster

Contents

Roadmap info from roadmap website

Installing a Local Cluster

To install and configure a Kubernetes cluster on CentOS 7 or Ubuntu, you would need to setup the prerequisites and requirements for setting up a Kubernetes cluster after which you would be installing the Kubernetes components, including Kubeadm, Kubelet, and Kubectl and then you’ll need to connect the master and the worker nodes. Once the connection is established you can check it by deploying application on the cluster.

Kubeadm, Kubelet, Kubectl

ComponentDescriptionRole in Kubernetes ClusterUsage
KubeadmA command-line tool that simplifies the process of setting up a Kubernetes cluster.Used to initialize and configure a Kubernetes cluster by setting up essential components like API Server, Controller Manager, etc.kubeadm init (to initialize a cluster), kubeadm join (to add nodes)
KubeletAn agent that runs on each node in the cluster, ensuring containers are running in Pods as defined by the Kubernetes control plane.Manages the lifecycle of containers on individual nodes, monitors health, and communicates node status to the control plane.Runs as a background service on each node; no direct CLI commands (configured via YAML or systemd)
KubectlA command-line tool used to interact with the Kubernetes API.Allows users to manage and control resources in the Kubernetes cluster by sending requests to the API Server.kubectl get, kubectl apply, kubectl delete, etc.

Resources

ToolMain Use CaseFeaturesStrengthsWeaknesses
Docker DesktopLocal developmentSimple UI, auto-image use in K8sMature, beginner-friendlyLimited metrics, proprietary
Rancher DesktopLocal developmentMetrics, UI, K8s dashboardOpen-source, polished UIOccasional performance issues
Podman DesktopContainer engineSupports Kind clustersOpen-source, Docker CLI compatibleLimited K8s integration
K3DCI pipelinesCLI-based, multi-node, fast startupExcellent for CI, lightweightLimited UI
KindCI, lightweight devCLI-based, multi-node supportReliable, good for small clustersSlower startup than K3D
MinikubeFlexible use casesVM & container support, UI, dashboardFeature-rich, broad compatibilitySlow startup
MicroK8sLocal with feature setCLI, metrics, version selectorSuitable for Ubuntu users, rich featuresSlowest startup time

MInikube

K3s

Documentation

First steps

Takeaways

K3D Tutorial

Own Tutorial

Step 1: Create the Cluster

Use the following command to create a K3D cluster with three server nodes, five agent nodes, and specific port mappings:

k3d cluster create --servers 3 --agents 5 -p "80:80@loadbalancer" -p "443:443@loadbalancer" --volume '/root/k3d/mycode:/code@agent:0'

Step 2: Verify Cluster Creation

Check if the cluster was created successfully:

k3d cluster list

Step 3: Update Kubernetes Configuration

Export the kubeconfig for the created cluster:

k3d kubeconfig get <CLUSTER_NAME> > ~/.kube/config

Step 4: Confirm Kubernetes Context

Ensure Kubernetes is using the correct context:

kubectl config current-context

The output should show k3d-<CLUSTER_NAME> as the current context.

Step 5: Access Traefik Dashboard

Forward the Traefik service to a local port for access:

kubectl port-forward -n kube-system "$(kubectl get pods -n kube-system | grep '^traefik-' | awk '{print $1}')" 9000:9000

You can access the Traefik dashboard here. More about kubernetes-kubernetes-installing-a-local-cluster-taefik

Step 6: Access Kubernetes Control Panel

Proxy the Kubernetes control panel to your localhost:

kubectl proxy

Access the control panel at 127.0.0.1:8001.

Step 7: Check Namespaces and Services

To list all services in all namespaces, use:

kubectl get services --all-namespaces

Overview of Services Up to This Point

NamespaceService NameTypeCluster IPExternal IP(s)PortsAge
defaultkubernetesClusterIP10.43.0.1<none>443/TCP23m
kube-systemkube-dnsClusterIP10.43.0.10<none>53/UDP, 53/TCP, 9153/TCP23m
kube-systemmetrics-serverClusterIP10.43.15.178<none>443/TCP23m
kube-systemtraefikLoadBalancer10.43.213.142172.19.0.2, 172.19.0.3, etc.80:32422/TCP, 443:30631/TCP22m
  • ClusterIP Services: Services like kubernetes, kube-dns, and metrics-server are limited to internal access, enabling core cluster operations like DNS resolution, API access, and metrics gathering.
  • LoadBalancer Service: The traefik service uses a LoadBalancer, allowing external traffic on HTTP/HTTPS to reach the cluster, making services publicly accessible if needed.

K3D Kubernetes Dashboard Tutorial

This section guides you through setting up and accessing the Kubernetes Dashboard for your K3D cluster.

To deploy the Kubernetes Dashboard, follow the steps below:

Step 1. Add the Kubernetes Dashboard Helm Repository

helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/

Step 2. Install the Kubernetes Dashboard

Deploy the dashboard in the kubernetes-dashboard namespace:

helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard

Step 3. Set Up Access Permissions

Create and apply a ServiceAccount and ClusterRoleBinding for admin access. This file is in https://github.com/npujol/kaos/blob/main/deploy/k3d/dashboard-adminuser.yaml:

  • Copy the following YAML into a new file, such as dashboard-adminuser.yaml:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard

apiVersion: v1
kind: Secret
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
  annotations:
    kubernetes.io/service-account.name: "admin-user"
type: kubernetes.io/service-account-token
  • Apply the file:
kubectl apply -f https://raw.githubusercontent.com/npujol/kaos/refs/heads/main/deploy/k3d/dashboard-adminuser.yaml

Step 4. Forward the Dashboard Port

Note: You may need to set up port forwarding or use kubectl proxy to access the dashboard locally.

kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443

Step 5. Access the Dashboard

  • Retrieve the access token for the admin-user account:
kubectl get secret admin-user -n kubernetes-dashboard -o jsonpath={".data.token"} | base64 -d

Go to the Kubernetes Dashboard and enter the token when prompted for authentication.

This configuration provides an accessible dashboard to monitor and manage workloads in your K3D cluster.

Here is django-example-app configuration

Monitoring tutorial

Step 1: Create monitoring namespace

kubectl create namespace monitoring

Step 2: Install Prometheus

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts -n monitoring
helm install "prometheus" prometheus-community/kube-prometheus-stack -n monitoring

Step 3: Install Grafana

TODO: Fix the url when the content is merged in the repo

helm install --values deploy/k3d/monitoring/loki.yaml loki grafana/loki -n monitoring

Step 4: Forward port

kubectl port-forward service/prometheus-grafana 3000:80 -n monitoring

Access to Grafana dashboard

Step 5: Forward Prometheus port

 kubectl port-forward service/prometheus-operated 9090:9090 -n monitoring

Access to Prometheus dashboard

#roadmap #kubernetes #kubernetes-kubernetes #ready #online