Skip to content

A guide along with scripts I used for setting up a kubernetes cluster.

Notifications You must be signed in to change notification settings

milesrack/kubernetes-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubernetes-setup

A guide along with scripts I used for setting up a kubernetes cluster.

Overview

We will setup one master node and at least one worker node to creake a kubernetes cluster. From the master node we can deploy containerized applications that will distribute the workload across the worker nodes.

Both the master and worker nodes will have Ubuntu 22.04 Server installed.

Requirements

  • Ubuntu 22.04 Server (tested with this script)
  • >= 2 GB RAM
  • >= 2 CPUs

Master Node

Run the setup script for the master node:

wget -q https://raw.githubusercontent.com/milesrack/kubernetes-setup/master/master-setup.sh -O - | bash

Copy the kubeadm join command in the output, this will allow worker nodes to join the cluster.

It may take a few minutes for all the pods to start running. We can view the running pods on the master node with the following command:

kubectl get pods -n kube-system

Worker Nodes

Use the following command to set the hostname:

sudo hostnamectl hostname node1

If you are setting up multiple worker nodes, make sure each hostname is unique (eg. node1, node2, node3).

Now run the setup script for the worker nodes:

wget -q https://raw.githubusercontent.com/milesrack/kubernetes-setup/master/node-setup.sh -O - | bash

Once the script has completed run the kubeadm join command generated by the master node:

sudo kubeadm join <IP>:6443 --token <TOKEN> --discovery-token-ca-cert-hash sha256:<hash>

Viewing Resources

Run the following command on the master node to view nodes in the cluster:

kubectl get nodes

For more verbose output (IP addresses, OS version, etc.):

kubectl get nodes -o wide

To show resource usage of nodes in the cluster:

kubectl top nodes

To show pods in the kubernetes system:

kubectl get pods -n kube-system

To show resource usage of pods in the kubernetes system:

kubectl top pods -n kube-system

Deploying Nginx

Run the following commands on the master node to configure the nginx service:

wget -q https://raw.githubusercontent.com/milesrack/kubernetes-setup/master/deployment.yaml -O - | kubectl apply -f -
wget -q https://raw.githubusercontent.com/milesrack/kubernetes-setup/master/service.yaml -O - | kubectl apply -f -

We can view the newly created pods with:

kubectl get pods

To show resource usage of the pods:

kubectl top pods

Navigate to http://<IP>:32000/ in your browser to view the running nginx server. Replace <IP> with the IP address of any of the worker nodes.

Resources