Category Archives: Kubernetes

Learn Kubernetes with DevOpsRoles.com. Access comprehensive guides and tutorials to orchestrate containerized applications and streamline your DevOps processes with Kubernetes.

Understanding Kubernetes OIDC

Introduction

Kubernetes, a popular container management tool, is increasingly used in the deployment and management of distributed applications. One of the biggest challenges in managing Kubernetes is ensuring safe and efficient user authentication and authorization. This is where OpenID Connect (OIDC) plays a crucial role.

Introduction Kubernetes OIDC

OpenID Connect is an authentication standard based on OAuth 2.0, which allows applications to authenticate users through identity providers. OIDC adds user and session information to OAuth, making it an ideal choice for authentication in cloud environments like Kubernetes.

Integrating OIDC with Kubernetes

To integrate OIDC with Kubernetes, you need to set up an OIDC identity provider and configure Kubernetes to use it. For example, if using Google Identity Platform, you would need to register an application and configure parameters such as client_id and client_secret in Kubernetes.

apiVersion: v1
kind: Config
users:
- name: kubernetes-admin
  user:
    auth-provider:
      config:
        client-id: YOUR_CLIENT_ID
        client-secret: YOUR_CLIENT_SECRET
        id-token: ID_TOKEN
        refresh-token: REFRESH_TOKEN
        idp-issuer-url: https://accounts.google.com
      name: oidc

Access Management and Role Assignment

Once OIDC is configured, you can use information from the ID token to determine user access in Kubernetes. Role-Based Access Control (RBAC) policies can be applied based on claims in the OIDC token, allowing you to finely tune access to Kubernetes resources in a powerful and flexible manner.

Best Practices and Recommendations

Security is the top priority when using OIDC in Kubernetes. Always ensure that sensitive information such as client_secret this is absolutely secure. Additionally, monitor and regularly update Kubernetes and OIDC provider versions to ensure compatibility and security.

  • Kubernetes OIDC-Client-Id
    • Used to identify the client in the OIDC provider configuration.
    • Essential for setting up authentication with the OIDC provider.
    • Must be unique and securely stored to prevent unauthorized access.
  • Kubernetes OIDC Authentication
    • Utilizes OIDC for user authentication, leveraging external identity providers.
    • Streamlines access management by using tokens issued by OIDC providers.
    • Reduces the overhead of managing user credentials directly in Kubernetes.
  • Kubernetes OIDC Login
    • Users log in to Kubernetes using OIDC tokens instead of Kubernetes-specific credentials.
    • Facilitates SSO (Single Sign-On) across multiple services that support OIDC.
    • Improves security by minimizing password usage and maximizing token-based authentication.
  • Kubernetes OIDC Keycloak
    • Keycloak can be used as an OIDC provider for Kubernetes.
    • Provides a comprehensive identity management solution capable of advanced user federation and identity brokering.
    • Offers extensive customization and management features, making it suitable for enterprise-level authentication needs.
  • Kubernetes OIDC Issuer
    • The OIDC issuer URL is the endpoint where OIDC tokens are validated.
    • Must be specified in the Kubernetes configuration to establish trust with the OIDC provider.
    • Plays a critical role in the security chain, ensuring that tokens are issued by a legitimate authority and are valid for authentication.

Conclusion

Kubernetes OIDC is a robust authentication solution that simplifies user management and enhances security for distributed applications. By using OIDC, organizations can improve security and operational efficiency. I hope will this your helpful. Thank you for reading the DevopsRoles page!

A Comprehensive Guide to Kubernetes RBAC Verbs List: From A to Z

Introduction

Kubernetes, a leading container management platform, offers a robust access control framework known as Role-Based Access Control (RBAC). RBAC allows users to tightly control access to Kubernetes resources, thereby enhancing security and efficient management.

Defining RBAC Verbs

  1. Get: This verb allows users to access detailed information about a specific object. In a multi-user environment, ensuring that only authorized users can “get” information is crucial.
  2. List: Provides the ability to see all objects within a group, allowing users a comprehensive view of available resources.
  3. Watch: Users can monitor real-time changes to Kubernetes objects, aiding in quick detection and response to events.
  4. Create: Creating new objects is fundamental for expanding and configuring services within Kubernetes.
  5. Update: Updating an object allows users to modify existing configurations, necessary for maintaining stable and optimal operations.
  6. Patch: Similar to “update,” but allows for modifications to a part of the object without sending a full new configuration.
  7. Delete: Removing an object when it’s no longer necessary or to manage resources more effectively.
  8. Deletecollection: Allows users to remove a batch of objects, saving time and effort in managing large resources.

Why Are RBAC Verbs Important?

RBAC verbs are central to configuring access in Kubernetes. They not only help optimize resource management but also ensure that operations are performed within the granted permissions.

Comparing with Other Access Control Methods

Compared to ABAC (Attribute-Based Access Control) and DAC (Discretionary Access Control), RBAC offers a more efficient and manageable approach in multi-user and multi-service environments like Kubernetes. Although RBAC can be complex to configure initially, it provides significant benefits in terms of security and compliance.

For example, a typical RBAC role might look like this in YAML format when defined in a Kubernetes manifest:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: default
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]

In this example, the Role named “pod-reader” allows the user to perform “get”, “watch”, and “list” operations on Pods within the “default” namespace. This kind of granularity helps administrators control access to Kubernetes resources effectively, ensuring that users and applications have the permissions they need without exceeding what is necessary for their function.

Conclusion

RBAC is an indispensable tool in Kubernetes management, ensuring that each operation on the system is controlled and complies with security policies. Understanding and effectively using RBAC verbs will help your organization operate smoothly and safely.

References

For more information, consider consulting the official Kubernetes documentation and online courses on Kubernetes management and security. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Are Kubernetes Secrets Encrypted?

Kubernetes Secrets Encrypted: Kubernetes has emerged as a pivotal player in managing containerized applications. However, with great power comes great responsibility, especially when handling sensitive information. Are Kubernetes secrets encrypted? This critical question underscores the need for robust security practices in Kubernetes deployments. Let’s dive into the essentials of Kubernetes secrets encryption.

Introduction

Kubernetes, a powerful orchestration tool, revolutionizes how we deploy and manage containerized applications. At its core, Kubernetes secrets offer a secure way to store and manage sensitive data such as passwords, tokens, and SSH keys. But the burning question remains: Are these secrets encrypted by default, and how can we ensure they are secure?

What Are Kubernetes Secrets?

Kubernetes secrets are objects that store sensitive data, such as passwords, OAuth tokens, and SSH keys, safeguarding this information within your Kubernetes pods and services. These secrets are designed to be more secure than storing sensitive data in pod specifications or in Docker images, but this does not inherently mean they are encrypted.

Current State of Encryption for Kubernetes Secrets

By default, Kubernetes secrets are stored as plaintext in the API server’s datastore, etcd. This means that without proper configuration, sensitive information could be exposed to unauthorized users with access to etcd. The revelation raises concerns about the intrinsic security measures provided by Kubernetes for secret management.

How to Encrypt Kubernetes Secrets

To enhance the security of Kubernetes secrets, administrators must take proactive steps. Encryption at rest, introduced in Kubernetes v1.7, allows you to encrypt secret data stored in etcd. Here’s a simplified guide to enable this feature:

  • Generate an Encryption Key: First, create a strong encryption key.
  • Configure the Encryption Provider: Kubernetes supports several encryption providers. Choose one and configure it with your encryption key.
  • Apply the Configuration: Update the Kubernetes API server configuration to use the encryption provider configuration file.
  • Verify Encryption: After applying the configuration, create a new secret and check etcd to ensure it’s encrypted.
  • Implementing encryption requires a careful approach to key management and access control, underscoring the need for comprehensive security practices.

Best Practices for Managing Kubernetes Secrets Encryption

Securing Kubernetes secrets goes beyond enabling encryption. Follow these best practices to fortify your secret management:

  • Least Privilege Access: Implement role-based access control (RBAC) to limit who can access Kubernetes secrets.
  • Secrets Rotation: Regularly rotate secrets to minimize the impact of potential exposures.
  • Audit and Monitor: Continuously monitor access to secrets and audit logs to detect unauthorized access attempts.
  • Use External Secrets Management Tools: Consider integrating external secrets managers like HashiCorp Vault, AWS Secrets Manager, or Google Cloud Secret Manager for enhanced security features.

Conclusion: Kubernetes Secrets Encrypted

The question, “Are Kubernetes secrets encrypted?” highlights a vital aspect of Kubernetes security. While secrets are not encrypted by default, Kubernetes offers mechanisms to secure them, provided administrators take the necessary steps to implement these features. By following the outlined best practices, you can significantly enhance the security of your Kubernetes secrets, ensuring your sensitive information remains protected.

Kubernetes continues to evolve, and with it, the tools and practices for secure secret management. Staying informed and proactive in implementing security measures is paramount for safeguarding your deployments against evolving threats. Thank you for reading the DevopsRoles page!

How to Install CNI for Kubernetes: A Comprehensive Guide

Introduction

In this tutorial, How to Install CNI for Kubernetes. Container orchestration has become an indispensable part of modern IT infrastructure management, and Kubernetes stands out as a leading platform in this domain. One of the key components that contribute to Kubernetes’ flexibility and scalability is the Container Networking Interface (CNI). In this comprehensive guide, we’ll delve into the intricacies of installing CNI for Kubernetes, ensuring smooth communication between pods and services within your cluster.

What is CNI and Why is it Important?

Before we delve into the installation process, let’s understand the significance of the Container Networking Interface (CNI) in the Kubernetes ecosystem. CNI serves as a standard interface for configuring networking in Linux containers. It facilitates seamless communication between pods, enabling them to communicate with each other and external resources. By abstracting network configuration, CNI simplifies the deployment and management of containerized applications within Kubernetes clusters.

Preparing for Installation

Before embarking on the installation journey, it’s essential to ensure that you have the necessary prerequisites in place. Firstly, you’ll need access to your Kubernetes cluster, along with appropriate permissions to install CNI plugins. Additionally, familiarity with basic Kubernetes concepts and command-line tools such as kubectl will prove beneficial during the installation process.

Step-by-Step How to Install CNI for Kubernetes

Example: Installing Calico CNI Plugin

Install kubectl: If you haven’t already installed kubectl, you can do so by following the official Kubernetes documentation for your operating system. For example, on a Linux system, you can use the following command:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Once installed, verify the installation by running:

kubectl version --client

Choose Calico as the CNI Plugin: Calico is a popular CNI plugin known for its simplicity and scalability. To install Calico, you can choose from various deployment methods, including YAML manifests or Helm charts. For this example, we’ll use YAML manifests.

Download the Calico Manifests: Calico provides YAML manifests for easy deployment. Download the manifests using the following command:

curl https://docs.projectcalico.org/manifests/calico.yaml -O

Configure Calico: Before applying the Calico manifests to your Kubernetes cluster, you may need to configure certain parameters, such as the IP pool for pod IPs. Open the calico.yaml file in a text editor and modify the configuration as needed.

vi calico.yaml

Here’s an example configuration snippet specifying an IP pool:

- name: CALICO_IPV4POOL_CIDR
  value: "192.168.0.0/16"

Apply Calico Manifests to Kubernetes: Once you’ve configured Calico according to your requirements, apply the manifests to your Kubernetes cluster using kubectl:

kubectl apply -f calico.yaml

This command will create the necessary Kubernetes resources, including Custom Resource Definitions (CRDs), Pods, Services, and ConfigMaps, to deploy Calico within your cluster.

Verify Installation: After applying the Calico manifests, verify the successful installation by checking the status of Calico pods and related resources:

kubectl get pods -n kube-system

Conclusion

Installing Container Network Interface (CNI) plugins for Kubernetes is a critical step towards enabling seamless communication between containers within a Kubernetes cluster. This process, while it might seem intricate at first, can significantly streamline and secure network operations, providing the flexibility to choose from a wide array of CNI plugins that best fit the specific requirements of your environment. By following the best practices and steps outlined for the installation process, users can ensure that their Kubernetes cluster is equipped with a robust and efficient networking solution.

This not only enhances the performance of applications running on the cluster but also leverages Kubernetes’ capabilities to the fullest, ensuring a scalable, manageable, and highly available system. Whether you’re deploying on-premise or in the cloud, understanding and implementing CNI effectively can profoundly impact your Kubernetes ecosystem’s efficiency and reliability. . Thank you for reading the DevopsRoles page!

Step-by-Step Guide to Setting Up Rolling Updates in Kubernetes with Nginx

Introduction

In the realm of Kubernetes, ensuring zero downtime during application updates is crucial. Rolling Updates in Kubernetes provide a seamless way to update the application’s pods without affecting its availability. In this guide, we’ll walk through setting up rolling updates for an Nginx deployment in Kubernetes, ensuring your services remain uninterrupted.

Preparation

Before proceeding, ensure you have Kubernetes and kubectl installed and configured. This guide assumes you have basic knowledge of Kubernetes components and YAML syntax.

Deployment and Service Configuration

First, let’s understand the components of our .yaml file which configures both the Nginx deployment and service:

Deployment Configuration

  • apiVersion: apps/v1 indicates the API version.
  • kind: Deployment specifies the kind of Kubernetes object.
  • metadata: Defines the name of the deployment.
  • spec: Describes the desired state of the deployment:
    • selector: Ensures the deployment applies to pods with the label app: nginxdeployment.
    • revisionHistoryLimit: The number of old ReplicaSets to retain.
    • progressDeadlineSeconds: Time to wait before indicating progress has stalled.
    • minReadySeconds: Minimum duration a pod should be ready without any of its containers crashing, for it to be considered available.
    • strategy: Specifies the strategy used to replace old pods with new ones. Here, it’s set to RollingUpdate.
    • replicas: Number of desired pods.
    • template: Template for the pods the deployment creates.
    • containers: Specifies the Nginx container and its settings, such as image and ports.

Service Configuration

  • apiVersion: v1 indicates the API version.
  • kind: Service specifies the kind of Kubernetes object.
  • metadata: Defines the name of the service.
  • spec: Describes the desired state of the service:
    • selector: Maps the service to the deployment.
    • ports: Specifies the port configuration.

Implementing Rolling Updates in Kubernetes

To apply these configurations and initiate rolling updates, follow these steps:

Step 1. Create or update your deployment and service file named nginx-deployment-service.yaml with the content below.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginxdeployment
  revisionHistoryLimit: 3
  progressDeadlineSeconds: 300
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  replicas: 3
  template:
    metadata:
      labels:
        app: nginxdeployment
    spec:
      containers:
      - name: nginxdeployment
        # image: nginx:1.22
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginxservice
spec:
  selector:
    app: nginxdeployment
  ports:
    - protocol: TCP
      port: 80

Step 2. Apply the configuration using the command:

kubectl apply -f nginx-deployment-service.yaml

Step 3. To update the Nginx image or make other changes, modify the nginx-deployment-service.yaml file, and then reapply it. Kubernetes will handle the rolling update according to your strategy specifications.

Monitoring and Troubleshooting:

Monitor the update process using:

kubectl rollout status deployment/nginx-deployment

Check the status of your pods with:

kubectl get pods

If you need to revert to a previous version due to an issue, use:

kubectl rollout undo deployment/nginx-deployment

Conclusion

Rolling updates are essential for maintaining application availability and user satisfaction. By following this guide, you’ve learned how to set up and manage rolling updates for an Nginx deployment in Kubernetes. As you continue to work with Kubernetes, remember that careful planning and monitoring are key to successful deployment management. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to Install a Helm Chart on a Kubernetes Cluster

Introduction

In this blog post, we’ll explore the steps needed how to install a Helm chart on a Kubernetes cluster. Helm is a package manager for Kubernetes that allows users to manage Kubernetes applications. Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.

How to Install a Helm Chart

Prerequisites

Before we begin, make sure you have the following:

  • A running Kubernetes cluster
  • The kubectl command-line tool, configured to communicate with your cluster
  • The Helm command-line tool installed

Step 1: Setting Up Your Environment

First, ensure your kubectl is configured to interact with your Kubernetes cluster. Test this by running the following command:

kubectl cluster-info

If you see the cluster details, you’re good to go. Next, install Helm if it’s not already installed. You can download Helm from Helm’s official website.

Step 2: Adding a Helm Chart Repository

Before you can install a chart, you need to add a chart repository. Helm charts are stored in repositories where they are organized and shared. Add the official Helm stable charts repository with this command:

helm repo add stable https://charts.helm.sh/stable

Then, update your charts list:

helm repo update

Step 3: Searching for the Right Helm Chart

You can search for Helm charts in the repository you just added:

helm search repo [chart-name]

Replace [chart-name] with the name of the application you want to install.

Step 4: Installing the Helm Chart

Once you’ve found the chart you want to install, you can install it using the following command:

helm install [release-name] [chart-name] --version [chart-version] --namespace [namespace]

Replace [release-name] with the name you want to give your deployment, [chart-name] with the name of the chart from the search results, [chart-version] with the specific chart version you want, and [namespace] with the namespace where you want to install the chart.

Step 5: Verifying the Installation

After installing the chart, you can check the status of the release:

helm status [release-name]

Additionally, use kubectl to see the resources created:

kubectl get all -n [namespace]

Conclusion

Congratulations! You’ve successfully installed a Helm chart on your Kubernetes cluster. Helm charts make it easier to deploy and manage applications on Kubernetes. By following these steps, you can install, upgrade, and manage any application on your Kubernetes cluster.

Remember, the real power of Helm comes from the community and the shared repositories of charts. Explore other charts and see how they can help you in your Kubernetes journey. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Kubernetes RBAC (Role-Based Access Control)

Introduction

In Kubernetes RBAC is a method for controlling access to resources based on the roles assigned to users or service accounts within the cluster. RBAC helps to enforce the principle of least privilege, ensuring that users only have the permissions necessary to perform their tasks.

Kubernetes RBAC best practices

Kubernetes create Service Account

Service accounts are used to authenticate applications running inside a Kubernetes cluster to the API server. Here’s how you can create a service account named huupvuser:

kubectl create sa huupvuser
kubectl get sa

The result is as follows:

Creating ClusterRole and ClusterRoleBinding

Creating a ClusterRole

A ClusterRole defines a set of permissions for accessing Kubernetes resources across all namespaces. Below is an example of creating a ClusterRole named test-reader that grants read-only access to pods:

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: test-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]

Apply the ClusterRole:

kubectl apply -f clusterrole.yml

Creating a ClusterRoleBinding

A ClusterRoleBinding binds a ClusterRole to one or more subjects, such as users or service accounts, and defines the permissions granted to those subjects. Here’s an example of creating a ClusterRoleBinding named test-read-pod-global that binds the test-reader ClusterRole to the huupvuser service account:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: test-read-pod-global
subjects:
- kind: ServiceAccount
  name: huupvuser
  apiGroup: ""
  namespace: default
roleRef:
  kind: ClusterRole
  name: test-reader
  apiGroup: rbac.authorization.k8s.io

Apply the ClusterRoleBinding:

kubectl apply -f clusterrolebinding.yaml

Combined Role YAML

For convenience, you can combine the ClusterRole and ClusterRoleBinding into a single YAML file for easier management. Here’s an example role.yml:

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: test-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: test-read-pod-global
subjects:
- kind: ServiceAccount
  name: huupvuser
  apiGroup: ""
  namespace: default
roleRef:
  kind: ClusterRole
  name: test-reader
  apiGroup: rbac.authorization.k8s.io

Apply the combined YAML file:

kubectl apply -f role.yml

Verify ClusterRole and ClusterRoleBinding:

kubectl get clusterrole | grep test-reader
kubectl get clusterrolebinding | grep test-read-pod-global

The result is as follows.

Delete ClusterRole and ClusterRoleBinding:

kubectl delete clusterrole test-reader
kubectl delete clusterrolebinding test-read-pod-global

The result is as follows.

Conclusion

we’ve explored the basics of Role-Based Access Control (RBAC) in Kubernetes RBAC best practices. Through the creation of Service Accounts, ClusterRoles, and ClusterRoleBindings, we’ve demonstrated how to grant specific permissions to users or service accounts within a Kubernetes cluster.

RBAC is a powerful mechanism for ensuring security and access control in Kubernetes environments, allowing administrators to define fine-grained access policies tailored to their specific needs. By understanding and implementing RBAC effectively, organizations can maintain a secure and well-managed Kubernetes infrastructure. I hope will this your helpful. Thank you for reading the DevopsRoles page!

A Comprehensive Guide to Validating Kubernetes Cluster Installed using Kubeadm

Introduction

When setting up a Kubernetes cluster using Kubeadm, it’s essential to validate the installation to ensure everything is functioning correctly. In this blog post, we will guide you through the steps to Validating Kubernetes Cluster Installed using Kubeadm and Kubectl.

Learn how to validate your Kubernetes cluster installation using Kubeadm and ensure smooth operations. Follow our step-by-step guide for easy validation.

You have Installed Kubernetes using Kubeadm on Ubuntu: A Step-by-Step Guide

Validating Kubernetes Cluster Installed using Kubeadm: Step-by-Step Guide

Validating CMD Tools: Kubeadm & Kubectl

First, let’s check the versions of Kubeadm and Kubectl to ensure they match your cluster setup.

Checking “kubeadm” version

kubeadm version

Checking “kubectl” version

kubectl version

Make sure the versions of Kubeadm and Kubectl are compatible with your Kubernetes cluster.

Validating Cluster Nodes

Next, we need to ensure that all nodes in the cluster, including both Master and Worker nodes, are in the “Ready” state.

To check the status of all nodes:

kubectl get nodes
kubectl get nodes -o wide

This command will display a list of all nodes in the cluster along with their status. Ensure that all nodes are marked as “Ready.”

Validating Kubernetes Components

It’s crucial to verify that all Kubernetes components on the Master node are running correctly.

To check the status of Kubernetes components:

kubectl get pods -n kube-system
kubectl get pods -n kube-system -o wide

This command will show the status of various Kubernetes components in the kube-system namespace. Ensure that all components are in the “Running” state.

Validating Services: Docker & Kubelet

To ensure the proper functioning of your cluster, we need to validate the services Docker and Kubelet on all nodes.

Checking Docker service status

systemctl status docker

This command will display the status of the Docker service. Ensure that it is “Active” and running without any errors.

Checking Kubelet service status

systemctl status kubelet

This command will show the status of the Kubelet service. Verify that it is “Active” and running correctly.

Deploying Test Deployment

To further validate your cluster, let’s deploy a sample Nginx deployment and check its status.

Deploying the sample “nginx” deployment:

kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml

This command will create the Nginx deployment in your cluster.

Validate the deployment:

kubectl get deploy
kubectl get deploy -o wide

These commands will display the status of the Nginx deployment, including the number of replicas and the desired and current states.

Check if the pods are in the “Running” state:

kubectl get pods
kubectl get pods -o wide

Make sure all pods are running without any errors.

Verify that containers are running on the respective worker nodes:

docker ps

This command will show the running containers on each worker node. Ensure that the Nginx containers are running as expected.

Delete the deployment:

kubectl delete -f https://k8s.io/examples/controllers/nginx-deployment.yaml

This command will delete the Nginx deployment from your cluster.

Conclusion

By following these steps, you can validate your Kubernetes cluster installation using Kubeadm and Kubectl. It’s essential to ensure that all the components, services, and deployments are running correctly to have a reliable and stable Kubernetes environment. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Installing Kubernetes using Kubeadm on Ubuntu: A Step-by-Step Guide

Introduction

Kubernetes has emerged as the go-to solution for container orchestration and management. If you’re looking to set up a Kubernetes cluster on a Ubuntu server, you’re in the right place. In this step-by-step guide, we’ll walk you through the process of installing Kubernetes using Kubeadm on Ubuntu.

Prerequisites

I have created 3 VMs for Kubernetes Cluster Nodes to Cloud Google Compute Engine (GCE)

  • Master(1): 2 vCPUs – 4GB Ram
  • Worker(2): 2 vCPUs – 2GB RAM
  • OS: Ubuntu 16.04 or CentOS/RHEL 7

I have configured Firewall Rules Ingress in Google Compute Engine (GCE)

  • Master Node: 2379,6443,10250,10251,10252
  • Worker Node: 10250,30000-32767

Installing Kubernetes using Kubeadm on Ubuntu

Set hostname on Each Node

# hostnamectl set-hostname "k8s-master"    // For Master node
# hostnamectl set-hostname "k8s-worker1"   // For 1st worker node
# hostnamectl set-hostname "k8s-worker2"   // For 2nd worker node

Add the following entries in /etc/hosts file on each node

192.168.1.14   k8s-master
192.168.1.16   k8s-worker1
192.168.1.17   k8s-worker2

Disable Swap and Bridge Traffic

Kubernetes does not work well with swap enabled. Run it on MASTER & WORKER Nodes

Disable SWAP

# swapoff -a
# sed -i.bak -r 's/(.+ swap .+)/#\1/' /etc/fstab

Load the following kernel modules on all the nodes,

# tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
# modprobe overlay
# modprobe br_netfilter

Set the following Kernel parameters for Kubernetes, run beneath tee command

# tee /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

Reload the above changes

# sysctl --system

For example, The output terminal of worker1.

Installing Docker

Run it on MASTER & WORKER Nodes. Kubernetes requires a container runtime, and Docker is a popular choice. To install Docker, run the following commands:

apt-get update  
apt-get install -y  apt-transport-https ca-certificates curl software-properties-common gnupg2

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

Installing Docker

apt-get update && sudo apt-get install \
  containerd.io=1.6.24-1 \
  docker-ce=5:20.10.24~3-0~ubuntu-$(lsb_release -cs) \
  docker-ce-cli=5:20.10.24~3-0~ubuntu-$(lsb_release -cs)

For example, The output terminal is as below:

Setting up the Docker daemon

cat <<EOF | sudo tee /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

mkdir -p /etc/systemd/system/docker.service.d

Start and enable the docker

systemctl daemon-reload
systemctl enable docker
systemctl restart docker
systemctl status docker

Install Kubeadm, Kubelet, and Kubectl

Add the Kubernetes repository and install Kubeadm, Kubelet, and Kubectl

apt-get update && sudo apt-get install -y apt-transport-https curl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

Installing Kubeadm, Kubelet, Kubectl

apt-get update
apt-get install -y kubelet kubeadm kubectl

apt-mark hold kubelet kubeadm kubectl

Start and enable Kubelet

systemctl daemon-reload
systemctl enable kubelet
systemctl restart kubelet
systemctl status kubelet

Initializing CONTROL-PLANE

Run it on MASTER Node only. On your master node, initialize the Kubernetes cluster with the command below:

kubeadm init

Make note of the kubeadm join command that’s provided at the end; you’ll need it to join worker nodes.

Installing POD-NETWORK add-on

Run it on MASTER Node only

For kubectl

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

Installing “Weave CNI” (Pod-Network add-on)

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

NOTE: There are multiple CNI Plug-ins available. You can install a choice of yours. In the case above commands don’t work, try checking the below link for more info

Joining Worker Nodes

Run it on WORKER Node only

On your worker nodes, use the kubeadm join command from above kubeadm init output to join them to the cluster.

kubeadm join <...>

Run this command IF you do not have the above join command and/or create a NEW one.

kubeadm token create --print-join-command

Verify the Cluster

On the master node, ensure your cluster is up and running

kubectl get nodes

You should see the master node marked as “Ready” and any joined worker nodes.

Conclusion

Congratulations! You’ve successfully installed Kubernetes using Kubeadm on Ubuntu. With your Kubernetes cluster up and running, you’re ready to deploy and manage containerized applications and services at scale.

Kubernetes offers vast capabilities for container orchestration, scaling, and management. As you become more familiar with Kubernetes, you can explore advanced configurations and features to optimize your containerized environment.

I hope will this your helpful. Thank you for reading the DevopsRoles page!

Additional Resources:

Exploring the Docker and Kubernetes comparison

Introduction

Docker and Kubernetes are both open-source container platforms that enable the packaging and deployment of applications. We will Unravel the Enigmatic Docker and Kubernetes comparison.

In the realm of modern software deployment, where technology evolves at the speed of light, two names reign supreme: Docker and Kubernetes.

These two technological titans have transformed the landscape of application development, but they often find themselves in the spotlight together, leaving many wondering: what’s the real difference between Docker and Kubernetes? Buckle up as we embark on an illuminating journey through the cosmos of containers and orchestration.

What is Docker: The Art of Containerization

Docker, launched in 2013, is the pioneer in containerization technology. At its core, Docker allows developers to package an application and its dependencies, including libraries and configurations, into a single unit called a container.

Imagine Docker as a master craftsman, wielding tools to sculpt applications into self-contained, portable entities known as containers. Docker empowers developers to encapsulate an application along with its dependencies, libraries, and configurations into a single unit. This container becomes a traveler, capable of seamlessly transitioning between development environments, testing stages, and production servers.

The allure of Docker lies in its promise of consistency. No longer must developers grapple with the frustrating “it works on my machine” dilemma. Docker containers ensure that an application behaves the same way regardless of where it’s run, minimizing compatibility woes and facilitating smoother collaboration among developers.

What is Kubernetes: The Cosmic Choreographer

While Docker handles the creation and management of containers, Kubernetes steps in to manage the orchestration and deployment of these containers at scale. Launched by Google in 2014, Kubernetes provides a powerful solution for automating, scaling, and managing containerized applications.

In this cosmic dance of software deployment, Kubernetes steps onto the stage as a masterful choreographer, orchestrating the movement of containers with finesse and precision. Kubernetes introduces the concept of pods groups of interconnected containers that share network and storage resources. This dynamic entity enables seamless load balancing, ensuring smooth traffic distribution across the dance floor of application deployment.

Yet, Kubernetes offers more than elegant moves. It’s a wizard of automation, capable of dynamically scaling applications based on demand. Like a cosmic conductor, Kubernetes monitors the performance of applications and orchestrates adjustments, ensuring that the performance remains stellar even as the audience and the users grow.

Docker and Kubernetes comparison

Docker vs Kubernetes Pros and cons

Key Differences and Complementary Roles

While Docker and Kubernetes fulfill distinct roles, they synergize seamlessly to offer a holistic solution for containerization and orchestration. Docker excels in crafting portable and uniform containers that encapsulate applications, while Kubernetes steps in to oversee the intricate dance of deploying, scaling, and monitoring these containers.

Consider Docker the cornerstone of containerization, providing the essential building blocks that Kubernetes builds upon. Through Docker, developers elegantly wrap applications and dependencies in containers that maintain their coherence across diverse environments, from the intimate realms of development laptops to the grand stages of production servers.

On the contrasting side of the spectrum, Kubernetes emerges as the maestro of container lifecycle management. Its genius lies in abstracting the complex infrastructure beneath and orchestrating multifaceted tasks load balancing, scaling, mending, and updating with automated grace. As organizations venture into vast container deployments, Kubernetes emerges as the compass, ensuring not only high availability but also the optimal utilization of resources, resulting in a symphony of efficiency.

In conclusion

Docker and Kubernetes, though distinct technologies are interconnected in the world of modern software deployment. Docker empowers developers to create portable and consistent containers, while Kubernetes takes the reins of orchestration, automating the deployment and scaling of those containers. Together, they offer a robust ecosystem for building, deploying, and managing applications in today’s fast-paced and ever-changing technology landscape.

Thank you for reading Docker and Kubernetes comparison. I hope will this your helpful. Thank you for reading the DevopsRoles page!