Quote
Hi @all, Itβs me again, BTW session 2 of kubewekend is already publish if you read the currently message, LOL π. Today we will learn and practice with
Ansible
andkind
inside the machine we provision and build in previous session, Read at: Kubewekend Session 1, not long as well, letβs digest to new session π«
List of topics in series
Why I choose Ansible
and kind
?
Quote
Just like usual, we will find the reason why I choose
Ansible
andKind
for targets to provideKubernetes
in locally
Ansible
and what can we do with one ?
IYKYK, I have a topic which write about Ansible, and how I use ansible to provisioning AWS Cloud
, that like crazy and powerful tools with huge community support. I hope you can find well about that at: Ansible, Terraform and your first infrastructure
Question
A couple question refer about what different between
Ansible
andTerraform
? With me they are kind of similar nowaday,Terraform
can do a job likeAnsible
, and vice versa, submit role like IaC (Infrastructure as Code). But not at all,Ansible
is releasing not target like IaC, but it use for Configuration, because you can image usuallyAnsible
will do task job behind the scene, like set up environment and configuration machine and use connection likessh
, butAnsible
is evolving nowaday, and you can do furthermore things with one, super cool.
Get the official documentation to understand more about Ansible
, read more at Introduction to Ansible
Info
Ansible
Providing open-source automation that reduces complexity and runs everywhere. Using Ansible lets you automate virtually any task. Here are some common use cases for Ansible:
- Eliminate repetition and simplify workflows
- Manage and maintain system configuration
- Continuously deploy complex software
- Perform zero-downtime rolling updates
Ansible uses simple, human-readable scripts called playbooks to automate your tasks. You declare the desired state of a local or remote system in your playbook. Ansible ensures that the system remains in that state.
Following the Ansible, Ansible is designed for
- Agent-less architecture
- Simplicity
- Scalability and flexibility
- Idempotence and predictability
Quote
Thinking about you have 100 machine in company, and you canβt loop the job for setting up one machine for hundred, you need
Ansible
to parallel configuration with same workflow to be ensure we will not mistake, you put all machines to same network, give thehosts
configuration, and runansible
with cup of coffee, that actually powerfulansible
can bring for us π
Setup Ansible
for your machine
Warning
Because
Ansible
is running only on Linux or Mac system, so you need to ensure useWSL
(For windows) or Linux machine for performAnsible
You can simply to install ansible
via pip
command of python, but you need python version >=
3.9 at least for stabling use ansible
. Use official documentation if you meet the problems
You can use ansible --version
to validate your progress is alright or not, double check that and we will move to Kind
, π
What is kind
?
For fun fact, if you search on kind
in internet like Google, you will not find anything about this tool on the head, for sure but if you find Kind Cluster
that will help you choose right location of kind
. Or simply access at Kind documentation, LOL π₯², more pleasant things inside their github
Quote
With me,
kind
is such helpful tool, and easily to management Kubernetes cluster, honestly when you work withk3s
,minikube
that cause you a lot trouble when you not follow those documentation.kind
is easily to run, just needcontainer runtime
likedocker
and you have completelykubernetes
in locally to practical, how cool is it !!! π₯Ά
So we reach to official definition to understand what is kind
Info
kind
kindΒ is a tool for running local Kubernetes clusters using Docker container βnodesβ.
kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.
You can use go
to install kind
, and setup with go install
LOL very simple π. kind
contain some pleasant things, include
- GoΒ packagesΒ implementingΒ cluster creation,Β image build, etc.
- A command line interface (
kind
) built on these packages. - DockerΒ image(s)Β written to run systemd, Kubernetes, etc.
kubetest
Β integration also built on these packages (WIP)
kind bootstraps each βnodeβ withΒ kubeadm. For more details seeΒ the design documentation.
Like I said kind
is very easily to use, just need docker
and we know your have machine in session 1, which setup container runtime is docker
inside. We will use ansible
to assume the task to deploy local cluster kubernetes
with kind on practical part
Initial design of kind
Info
When you work with
kind
, you have full components to work withkubernetes
cluster like real in cloud services, it divide into go packages, and implementing most of functionality, CLI for users andnode
images - which image built in and just need pull to setup cluster like you expectation if you want to work for in Cloud.
So if you setup the kind
, you will receive features from team project, including
- runs very cheap clusters that any developer can locally replicate
- integrates with our tooling
- is thoroughly documented and maintainable
- is very stable, and has extensive error handling and sanity checking
- passes all conformance tests
After you bring up the kind
, you will have the cluster with include the services like
And if you have kubectl
inside your host, kind
will automatically export kubeconfig
for your purpose to give bride to contact with your cluster, how cool is that π
One more thing, follow the cycle life of kind
and node image, I think that contain all versions are close to reality, you can retrieve that from Dockerhub - kind/node
That @all technologies for this session, we will move to practical part and learn more about ansible
, and figure out the way use that to provisioning your kubernetes
locally cluster with kind
Alternative of kind
You can choose another tools for setup locally kubernetes
, with kind
you will receive the simple things to set up, and do not need and understand to much way for self-hosted kubernetes. But if you want to practice more, and come up with more flexibility, so you can checkout with some another example
- RKE : RKE2, also known as RKE Government, is Rancherβs next-generation Kubernetes distribution.
- minikube : Β Quickly sets up a local Kubernetes cluster on macOS, Linux, and Windows
- k3s : Lightweight Kubernetes. Easy to install, half the memory, all in a binary of less than 100 MB.
- microk8s : Β The easiest and fastest way to get Kubernetes up and running.
- k0s : An open source, all-inclusive Kubernetes distribution, which is configured with all of the features needed to build a Kubernetes cluster
Warning
But recommendation from me, If you do not familiar with system, please choose
kind
that easily to hand on withkubernetes
in the first time
Practical with ansible
and kind
Quote
Purpose in lab session 2 about using the
ansible
to configurationkind
cluster inside the machine which built from session 1. You will about how to useansible-playbook
withhosts
andinventories
to delivery parameterize on configuration which use forkind
. Okay now, we will inspect it
To easily follow what is practical, you can access the lab on my github - kubewekend
If you read the part above, ensure you have ansible
in your host, therefore I skip this step. I will drop down some workflow to make your provision become smooth, include
- Define
hosts
file for ansible can detection your location, and methodology to access your host which provided byvagrant
- Next, you need to define
kind-config
and parameterizetemplate
to give configuration which use when setupkubernetes
cluster - Next, you will define
tasks
, one concept ofansible
to define the workflow to configkubernetes
withkind
- Connect host and retrieve the result to validate succeed provisioning
kubernetes
cluster
Define hosts
That part is very important, the bridge help you connect between ansible
and vagrant
host. For easily to understand, I think about writing script to help you automation retrieve which host become online, here is the script
Let take a look about script, you can image my script will use vagrant
to
- Retrieve the
status
of machine in running state, that are really useful for helping you understand target, and use that for seessh-config
- If you know about list of
VM
in running state, you can retrieve the couple of things to setup about your host likeuser
host
andport
, that really define base onhosts
template come from official documentation. Export that definition to yourhosts
file - Lastly, the script will automate add key which retrieve from profile of
vagrant
to get the private_key which help you access tovagrant
host via them
Warning
On the situation, you have create a new virtual machine but your know_hosts have include the key from old configuration, you need to make sure to delete that. For e.g, use command
That all, you can use ssh-add -L
to retrieve your private_key
of running machine import in ssh-session
to do next-things
And you can execute the script with command
Definition configuration for kind
In this part, we will write the configuration file which help you define your cluster base on your decision, It means you can change something inside cluster, such as
- CNI (Container Network Interface)
- Subnet for Pod and Service
- Feature gate of Kubernetes Cluster
- Change configuration inside
kubeadm
,kubelet
andkube-apiserver
- You can change
kube-proxy
mode - Setup node role, and how much node you want to implement
And more feature is in develop progress of kind
project, but is provide that into template and take note some situations, you can check on below
That huge and a lot, you will be messed up on the first meet, but it just really simple and you can give some basically configuration, brief like
- namecluster: Set name of cluster
- networking: Modify and configuration subnet of pods and services of cluster
- cni: Disable default cni, because I will use customize
cilium
, aebpf
platform - kube-proxy: Use
iptables
, but on feature we can usecilium
- role: Just use only control plane role
Warning
For preventing error, usually cluster will exist at least on control plane, so can deploy only worker node, that will cause you have problem when configuration different role for your node to make that become HA, but donβt worry we will inspect later
That all the purpose I want to change, and make it become different with default. So you know your kind-config.yaml
is writing in jinja2
and you can see {{ }}
bracket, and that can become to place where call by tasks
inside ansible
. You can image host_vars
like
and each key-values, it will map into kind-config.yaml
with corresponding values. kind-config.yaml
is already to use, just define ansible
for doing stuff.
Write Ansible, and execute the script
In the last of stage, we need to write the script to telling with ansible
do configuration for us in bring up kind
cluster.
Just for sure you have connection, you can use ping
- basic module that ansible
offer for us, read more about that in walkthrough documentation
and result if return success
, you are done for connecting to machine with ssh
, and failure occur so you need to re-check again
You can move on the definition steps for ansible playbook, that component will put some configuration about installing kind
tool and use command to operate kind
cluster. Just for help you understand more situations, I try to put more complicated block to handle that. Let explain that
With this configuration, you have control workflow below 2 task
install_common
: For installingkind
and package dependencies forlinux
machinesetup_kind
: For setupkind
cluster with optional choosehost_vars
base environment you set when runansible
To understand syntax, I recommend you read about syntax when you try write playbooks of ansible
. Read more at: Ansible playbooks, and one more thing if you want to do more configuration but easily to prompt ansible
, i recommend you use ansible
extension in VSCode, with help you a lot to understand and prevent mistake when you write the ansible
After setup your ansible playbooks
, you need to use ansible-playbook
command to practice with your playbooks, and yup it will be kind of fun things
That is basic command, you need to provide some optional before you can use playbook above, including
-i
:PATH of your inventories--extra-vars
: Additional variables you want to set on run-time ofansible
, with key-value type . E.g:host_name=k8s-master-machine
(NOTICE: You can use thisextra_vars
for multiple times)--tags
: Set the tasks tagged with values, it means you execute that sequential tasks base on this optional (NOTICE: You can use this one for multiple times)
And in the end you choose your ansible playbook which you want to play, and you can perform task with execution with your expectation
When you see that result return with no failure, you can easily check vagrant to see kind
cluster is actually bring up with ssh
command
Your cluster will actually work, and ready to retrieve from kubectl
. You can easily check kubeconfig
is automatically generate and store at .kube/config
Validate kind
cluster
To make conversation with kind
, you can use kubectl
to installing that, you can easily download that for Win, Mac or Linux. For example, I will provide some command to install that
You can validate that on vagrant
host with command version
So next, (Optional) you will use kind
to see your host does exist context or not
If your shell expose something except error, you will see a lots of configuration with certificate is base64
encode, kubectl
will use this context to call and work with kind
cluster
First of all use list all configuration which have inside host
And you can use config that with command
accessableaccessable
Now you are in kind
cluster, just use kubectl get all -A
to show all things inside currently container
And now you have full accessible to kind
cluster, and we will talk about deep about cluster on next session
Conclusion
Success
That is end of session 2, hope you enjoy and learn about new things, include
ansible
andkind
, and the way we can use that tools to make valuable for yourself. In the end, you will have cluster in locally to practicekubernetes
that really cool and helpful for learning more aboutkubernetes
.
Quote
Give the appreciate for
kind
andKubernetes
community to bring up the powerful and easily tools to learn and play withkubernetes
, and more warmness toansible
in providing the powerful configuration language to handle incredible things, willing to learn more from of them. And give more thankful and grateful to you my audience, your readable will a part to make this adventure become more pleasant, therefore hope you and family well, stay safe and wait for next session, Bye bye π