Recommended Knowledge Beforehand:
- Basics of VM tools: VMware / Hyper-V / Virtualbox.
- Linux: using commands, vi text editors.
- Foundational DevOps understanding.
- CLI on local host: I use Git Bash for Windows; Linux/MacOS, native works.
- Azure Account-Create (Required//in order to use Azure resources)
- GCP Account-Create (Required//in order to use Google Cloud resources)
- Download Ubuntu VM template, preferrably version 18.04:
- On VMware / Hyper-V Clients.
- On VirtualBox Clients.
- Create four VMs using either VMware / Hyper-V / Virtualbox.
- Pick one to be the controller, doesn't matter which; the rest will be remotes.
- [NOTE] You will need to be aware of what the IPs of each VM / Node are.
Lab Example |
[ANSIBLE] This is the fastest option, contrary to how long these instructions are 😊. Use Ansible instead of manually copying. What this will do, is run a script on each node that automates most of the installation and configuration of Kubernetes. This won't automate everything, but will skip a good amount of redundant hassle.
- Navigate into the Controller Node / Control Plane Node (c1-cp1) and install git.
- [Run]
sudo apt update; sudo apt install git -y
- [Run]
- Clone repo into the Controller Node / Control Plane Node (c1-cp1).
- [Run]
git clone https://github.com/jedington/kubernetes-learning.git ~/kubernetes-learning/
- [Run]
- Changing permissions to allow execution of scripts to setup Ansible.
- [Run]
sudo chmod -R 755 ~/kubernetes-learning/01-Setup-Ansible
- [Run]
- Replace the default Ansible 'ansible.cfg' (configuration) file with our own.
- [Run]
sudo cp -f ~/kubernetes-learning/01-Setup-Ansible/ansible.cfg /etc/ansible/ansible.cfg
- [Run]
- Use
controller-setup.sh
to install python and ansible.- [NOTE] You'll have to adjust IPs in the 'echo' of 'controller-setup.sh' to your Node IPs.
- [Run]
sudo vi ~/kubernetes-learning/01-Setup-Ansible/controller-setup.sh
- [REQUIRED] Edit to reflect your VMs. Two locations in the file to change per Node.
- Example--edit the IP addresses to reflect your host IPs
... 10.10.10.10 c1-cp1 10.10.10.11 c1-node1 10.10.10.12 c1-node2 10.10.10.13 c1-node3 ... c1-cp1 ansible_host=10.10.10.10 ansible_user=root ... c1-node1 ansible_host=10.10.10.11 ansible_user=root c1-node2 ansible_host=10.10.10.12 ansible_user=root c1-node3 ansible_host=10.10.10.13 ansible_user=root ...
- [Run]
- [Run]
sudo ~/kubernetes-learning/01-Setup-Ansible/controller-setup.sh
- [NOTE] You'll have to adjust IPs in the 'echo' of 'controller-setup.sh' to your Node IPs.
- Figure out auth for remote hosts, can use 'ssh-setup-example.sh'.
- [Run]
sudo ~/kubernetes-learning/01-Setup-Ansible/ssh-setup-example.sh
- [Note] this will prompt for the default passwords for each VM.
- [Run]
- Finally, run the Ansible playbook from the Controller Node.
- [Run]
sudo ~/kubernetes-learning/01-Setup-Ansible/ansible-playbook all-setup.yml
- [Run]
- Refer to '../02-PluralSight-Fundamentals/03/Demos/1-CreateControlPlaneNode-containerd.sh' and complete setup of the Control Plane Node from there.
- Continue to Anthony Nocentino's PluralSight guide. Keep in mind that much of installing Kubernetes has been automated, now its just further configuring the control node and running it. Along with pairing the remote nodes to the control node with the token process.
[SSH] This option is arguably quick if you're fully comfortable with SSH into clients and using 'git' to remotes. This option still automates the Kubernetes install, but you have to SSH to each Node.
- [All-Nodes] Install git.
- [Run]
sudo apt update; sudo apt install git -y
- [Run]
- [All-Nodes] Clone repo in a preferred local directory.
- [run]
git clone https://github.com/jedington/kubernetes-learning.git ~/kubernetes-learning/
- [run]
- [All-Nodes] Changing permissions to allow execution of scripts.
- [Run]
sudo chmod -R 755 ~/kubernetes-learning/01-Setup-Ansible
- [Run]
- [All-Nodes] Run the Kubernetes setup file.
- [Run]
sudo ~/kubernetes-learning/01-Setup-Ansible/kubernetes-ubuntu-setup.sh
- [Run]
- [Control-Plane-Node-only] Refer to '../02-PluralSight-Fundamentals/03/Demos/1-CreateControlPlaneNode-containerd.sh' and complete setup of the Control Plane Node from there.
- Continue to Anthony Nocentino's PluralSight guide. Keep in mind that much of installing Kubernetes has been done, now its just further configuring the control node and running it. Along with pairing the remote nodes to the control node with the token process.
If you have a PluralSight subscription, I recommend taking a look at Kubernetes Fundamentals by Anthony Nocentino.
[NOTE] Control Plane Node's IP address will vary; what's used as an example in the upcoming exercise files is: '172.16.94.10' This is the example IP address that will connect to the remote nodes.
- Kubernetes Fundamentals
- 02-PluralSight-Fundamentals > 02 > exploring-the-kubernetes-architecture-slides.pdf
- Install/Configure Kubernetes
- 02-PluralSight-Fundamentals > 03 > installing-and-configuring-kubernetes-slides.pdf
- Working with Kubernetes Cluster
- 02-PluralSight-Fundamentals > 04 > working-with-your-kubernetes-cluster-slides.pdf
NOTE: make sure to finish the remainder of setup from the above PDFs
Kubernetes Command Ref • Kubectl Ref • Cheatsheet Ref
- apply/create ---- creates resource(s)
- run ---- start a pod from an image
- explain ---- documentation of resource(s)
- delete ---- delete resource(s)
- get ---- list resource(s)
- describe ---- detailed resource(s) information
- exec ---- execute a command on a container
- logs ---- view logs on a container
[Examples] Useful commands for starting out
kubectl | [command] | [type] | [name] | [flags] |
---|---|---|---|---|
kubectl | -h | more | |||
kubectl | get | -h | more | ||
kubectl | run | -h | more | ||
kubectl | exec | -h | more | ||
kubectl | edit | -h | more | ||
kubectl | logs | -h | more | ||
kubectl | create | -h | more | ||
kubectl | delete | -h | more | ||
kubectl | explain | -h | more | ||
kubectl | describe | -h | more | ||
kubectl | expose | -h | more | ||
kubectl | get | events | --watch & |
[Examples] Imperatively using Kubernetes commands
kubectl | [command] | [type] | [name] | [flags] |
---|---|---|---|---|
kubectl | -h | more | |||
kubectl | get | -h | more | ||
kubectl | get | all | --all-namespaces | more | |
kubectl | get | pods | --namespace [example] -o wide | |
kubectl | get | pods | --output=yaml | |
kubectl | create | deployment | nginx | --image=nginx |
kubectl | explain | pods | --recursive | more | |
kubectl | describe | nodes | c1-cp1 | | more |
kubectl | create | deployment | hello-world | --image=gcr.io/google-samples/hello-app:1.0 |
kubectl | exec | -it hello-world | -- /bin/sh | |
kubectl | exec | -it hello-world | --container [example] -- /bin/bash | |
kubectl | logs | hello-world | --container [example] | |
kubectl | port-forward | pod | hello-world | 8080:8080 |
kubectl | describe | replicaset | hello-world | | more |
kubectl | expose | deployment | hello-world | --port=80 --target-port=8080 |
kubectl | describe | service | hello-world | |
kubectl | get | deployment | hello-world | -o yaml | more |
kubectl | edit | deployment | hello-world | |
kubectl | scale | deployment | hello-world | --replicas=10 |
kubectl | delete | deployment | hello-world | |
kubectl | delete | service | hello-world | |
kubectl | delete | pod | hello-world |
[Examples] Declaratively Deploying instead of Imperatively (w/ dry-runs > manifests)
#[1]
kubectl create deployment hello-world \
--image=gcr.io/google-samples/hello-app:1.0 \
--dry-run=client -o yaml > deployment.yaml
#[2]
kubectl apply -f deployment.yaml
#[3]
kubectl expose deployment hello-world \
--port=80 --target-port=8080 \
--dry-run=client -o yaml | more
#[4]
kubectl expose deployment hello-world \
--port=80 --target-port=8080 \
--dry-run=client -o yaml > service.yaml
#[5]
kubectl apply -f service.yaml
#[6]
sudo sed -i 's/replicas: 1/replicas: 20/' deployment.yaml
#[7]
kubectl apply -f deployment.yaml