Installation of Kubernetes in Production
Rohaan Joshi
PMP Certified Senior DevOps Engineer | AWS DevOps Professional | Kubernetes | AWS | 2x Azure | OpenShift | PCI Compliance | API Security | Ansible | Terraform | Docker | GitHub | GitLab | Splunk | Python | MLOps
Kubernetes, often abbreviated as K8s, is a powerful container orchestration platform that simplifies containerized applications' deployment, scaling, and management in a production environment. Nowadays most organizations are moving towards managed service but that doesn't give you control over infrastructure. In some critical Business cases like FinTech BFSI industries or government applications where the environment is hybrid or On-premises. Deploying Kubernetes in a production setting requires careful planning and adherence to best practices to ensure reliability, scalability, and security. Here's an overview of the steps involved in installing Kubernetes in a production environment:
1. Planning:
2. Container Runtime:
3. Cluster Initialization:
4. Networking:
5. Security:
6. Storage:
7. Monitoring and Logging:
8. High Availability and Scaling:
9. Upgrades and Maintenance:
10. Backup and Disaster Recovery:
11. Integration with CI/CD:
12. Documentation and Training:
Installing Kubernetes in a production environment is a complex but rewarding endeavor. Following best practices we are implementing for the demo. Regularly assessing and optimizing your setup to adapt to the evolving needs of your applications and users is the key to success.
Let's Install K8s on the Production environment
I use Amazon Web Services (AWS) EC2 general-purpose instances of t2.xlarge (4 Core CPU and 16 GB RAM). OS: AWS Linux2 Kernal version 5.10 hvm I used three instances one is master, and two are worker nodes.
Step 1: Spin up AWS EC2 instances
Step 2: Connect every instance by SSH
Step 3: Installation of container runtime in all three instances
# swtich user to root
sudo su -
yum install docker -y
Starting docker service
systemctl start docker
Step 4: Enabling permissive mode to install Kubernetes
As AWS Linux is based on Redhat and follows SELinux we have to give certain permission.
# Set SELinux in permissive mode (effectively disabling it)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
It helps containers to allow access to host filesystems.
Step 5: Adding Kubernetes repository to yum package manager
# This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF
To check repository has been added or not
$ yum repolist
Step 6: Installation of kubelet, kubeadm, and kubectl
领英推荐
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
Step 7: Enable the kubelet service before running kubeadm
sudo systemctl enable --now kubelet
Creating the Kubernetes Cluster
Step 1: Initialization of cluster
kubeadm init
To access the cluster as a regular user we need to execute the following commands
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
For root user
export KUBECONFIG=/etc/kubernetes/admin.conf
Let's fire Kubectl commands
Wait Wait Wait!!!
It's not your end game!
Simply go to AWS EC2 into the security group and enable all traffic to port 6443
Save the rules that's it
Let's make the Cluster
To connect master nodes to worker nodes execute the following command into those worker nodes (the token and certificate will be changed don't copy it)
kubeadm join 172.31.39.197:6443 --token tc202o.tz0vcoxnfyob5y78 \
--discovery-token-ca-cert-hash sha256:97f09b9654d6f71ccde527f9c318a4c4e2ca960aab5c8025168cc78994bf857b
Installation of Calico Operator
For communication with pods and nodes, we need to establish the network for that we are using the calico operator to Create the Network.
Step 1: Install the Tigera Calico operator and custom resource definitions.
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.2/manifests/tigera-operator.yaml
Step 2: Install Calico by creating the necessary custom resource. For more information on configuration options available in this manifest.
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.2/manifests/custom-resources.yaml
(only for single node cluster)
Step 3: Remove the taints on the control plane so that you can schedule pods on it
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
kubectl taint nodes --all node-role.kubernetes.io/master-
Confirm that you have a node in your cluster with the following command.
kubectl get nodes -o wide
kubectl get pods -A
Congratulations you finally configured and installed Kubernetes on the production cluster.
References
Building Cloudanix | YC S21 | Code to Cloud Security Platform
7 个月This is superb! Would like to publish a similar blog post from you on our website! (If you're interested in building one for us!). Also to add more depth to your article I'm sharing this article link that focuses on the Importance of Kubernetes Security! Do check ;) https://www.cloudanix.com/learn/importance-of-kubernetes-security
Startups Need Rapid Growth, Not Just Digital Impressions. We Help Create Omni-Channel Digital Strategies for Real Business Growth.
8 个月This guide sounds like a game-changer for anyone navigating the world of Kubernetes deployment! Ensuring a robust and efficient Kubernetes cluster is crucial for smooth operations in a production environment. Thanks for sharing such valuable insights and tips to optimize performance and scalability while simplifying deployment complexities. Can't wait to dive into this guide and level up my container orchestration skills!
DevOps Associate | 1X CKA certified | 1X AWS certified | DevOps | Terraform | Kubernetes | OpenShift | Ci-Cd | Git-Github | Cloud | Ansible | Docker | Maven | Jenkins | Splunk |
8 个月Very insightful....??
"Account Security Officer" with 22 yrs varied experience | Certifications: ISO27K, ITIL, PMP, CSM | Skills: ISO9/20/27K, BSS/OSS, CISA, CISSP, BCP/DRP, VAPT/CR, Azure500, Linux, Compliance, Audit, Risk, SDM, PM
8 个月An innovative way of writing article and in the last, Leonardo assures the readers of learning valuable information. Keep it up Rohaan!
Data Scientist | Senior Recruiter
8 个月#cfbr