Hello Friends ,Hope you guys doing absolutely well !😃
In Today’s article, we will create an Ansible role to set up a K8S cluster with multiple nodes in the AWS cloud.
So , Let’s get Begun ..
K ubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.
The name Kubernetes originates from Greek, meaning helmsman or pilot. Google open-sourced the Kubernetes project in 2014. Kubernetes combines over 15 years of Google’s experience running production workloads at scale with best-of-breed ideas and practices from the community.
Why you need Kubernetes and what it can do
Containers are a good way to bundle and run your applications. In a production environment, you need to manage the containers that run the applications and ensure that there is no downtime. For example, if a container goes down, another container needs to start. Wouldn’t it be easier if this behavior was handled by a system?
That’s how Kubernetes comes to the rescue! Kubernetes provides you with a framework to run distributed systems resiliently. It takes care of scaling and failover for your application, provides deployment patterns, and more. For example, Kubernetes can easily manage a canary deployment for your system.
Kubernetes provides you with:
- Service discovery and load balancing
- Storage orchestration
- Automated rollouts and rollbacks
- Automatic bin packing
- Secret and configuration management
K8S Multi Multi-Node Cluster
A Kubernetes cluster is a set of node machines for running containerized applications. If you’re running Kubernetes, you’re running a cluster.
At a minimum, a cluster contains a control plane and one or more compute machines, or nodes. The control plane is responsible for maintaining the desired state of the cluster, such as which applications are running and which container images they use. Nodes actually run the applications and workloads.
The cluster is the heart of Kubernetes’ key advantage: the ability to schedule and run containers across a group of machines, be they physical or virtual, on premises or in the cloud. Kubernetes containers aren’t tied to individual machines. Rather, they’re abstracted across the cluster.
Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn’t depend on agent software and has no additional security infrastructure, so it’s easy to deploy.
Ansible role is a set of tasks to configure a host to serve a certain purpose like configuring a service. Roles are defined using YAML files with a predefined directory structure. A role directory structure contains directories: defaults, vars, tasks, files, templates, meta, handlers.
Configure K8S Multi Node Cluster over AWS Cloud
Let’s Started ..
As we can see that we don’t have any host or instance running
Steps to Complete our task
1. Launching 3 AWS EC2 Instance with Ansible role
ansible-galaxy init ec2
In tasks file of ec2 role :
In vars file of ec2 role :
2. Setting Up Master Node and Worker Nodes
For Master/Controller Node,
Create role for configuring a Master :
ansible-galaxy init k8s-master
In tasks file of k8s-master role :
In vars file of k8s-master role :
For Worker Nodes,
Create role for configuring a Worker:
ansible-galaxy init k8s-worker
In tasks file of k8s-worker role :
In vars file of k8s-worker role :
In playbook setup.yml :
Run the playbook setup.yml
We can see that our playbook run successfully ✌
Now we can check is instances are launched and multinode cluster is setup or not ?
As we can see that our three instances are launched successfully…..
Now only thing to check is our k8s multi-node cluster is setup or not ?
we can check it by login into the master node and ask them How many nodes they have connected with command
kubectl get nodes
Finally our k8s multi-node cluster is ready 😃🙌
Thanks for stay tune ❗❗