Step 3 Deploy Kubernetes Cluster - truongnhatbui/techtrends GitHub Wiki
Now it's time for me to deploy TechTrends first Kubernetes cluster.
This section will focus on provisioning a vagrant box and installing a Kubernetes cluster using k3s.
Provision a Vagrant box locally and install Kubernetes with k3s.
Note: Make sure to have VirtualBox 6.1.16 or higher installed.
Step 1 - Install vagrant on your machine
Step 2 - Clone the techtrends repository using git commands
HTTPS
https://github.com/truongnhatbui/techtrends.git
SSH
[email protected]:truongnhatbui/techtrends.git
GITHUB CLI
gh repo clone truongnhatbui/techtrends
Vagrantfile
# set up the default terminal
ENV["TERM"]="linux"
Vagrant.configure("2") do |config|
# set the image for the vagrant box
config.vm.box = "opensuse/Leap-15.2.x86_64"
## Set the image version
# config.vm.box_version = "15.2.31.247"
# st the static IP for the vagrant box
config.vm.network "private_network", ip: "192.168.50.4"
# consifure the parameters for VirtualBox provider
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.cpus = 4
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
end
(Note: you need to be in the same repository as the Vagrantfile for this command to work)
# create a vagrant box using the Vagrantfile in the current directory
vagrant up
# SSH into the vagrant box
# Note: this command uses the .vagrant folder to identify the details of the vagrant box
vagrant ssh
Step 6 - Deploy a Kubernetes cluster using k3s
curl -sfL https://get.k3s.io | sh -
# Check for Ready node, takes maybe 30 seconds
k3s kubectl get node
Note: To access kubectl commands you need to become root by using sudo su - command.
Let's take a closer look at cluster configuration details.
kubeconfig
K3s stores the kubeconfig file under /etc/rancher/k3s/k3s.yaml path
API server - https://127.0.0.1:6443
authentication mechanism - username (admin) and password
The kubeconfig file and kubectl commands are the 2 main components that permits the interaction with a Kubernetes cluster.
(Note: you need to be root to access the kubeconfig file, use sudo su -
before using kubectl commands)
kubectl commands
kubectl cluster-info to get the control plane and add-ons endpoints
Kubernetes master is running at https://127.0.0.1:6443
CoreDNS is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy
kubectl get nodes - to get all the nodes in the cluster
NAME STATUS ROLES AGE VERSION
localhost Ready master 74m v1.18.9+k3s1
kubectl get nodes -o wide - to get extra details about the nodes, including internal IP
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
localhost Ready master 74m v1.18.9+k3s1 10.0.2.15 <none> openSUSE Leap 15.2 5.3.18-lp152.47-default containerd://1.3.3-k3s2
kubectl describe node node-name - to get all the configuration details about the node, including the allocated pod CIDR
kubectl describe node localhost | grep CIDR
PodCIDR: 10.42.0.0/24
PodCIDRs: 10.42.0.0/24
Now you should have a Kubernetes cluster up and running. Examine the cluster and identity of the following details.
Use the blank space to record your answer if necessary,
Reflect
From the kubeconfig, identify:
the IP and port of the API server authentication mechanism Note: Refer to the main k3s installation guide, to find the location of the kubeconfig file.
Your reflection
Things to think about See the solution page for details.
Reflect
From the cluster using kubectl commands to identify:
endpoints of the control plane and add-ons amount of nodes node internal IP the pod CIDR allocate to the node
Note: To access kubectl commands you need to become root by using sudo su - command.
Your reflection
Things to think about
See the solution page for details.
Solution: Deploy Your First Kubernetes Cluster