Kubernetes  architecture, installation, components and configuration

Kubernetes architecture, installation, components and configuration

·

7 min read

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Kubeadm is a tool used to bootstrap a Kubernetes cluster. It automates many of the manual steps involved in setting up a Kubernetes cluster, making it easier to get started with Kubernetes.

In this blog post, we will cover the Kubernetes architecture, installation using Kubeadm, components, and configuration, including code examples.

Kubernetes Architecture :

The Kubernetes architecture consists of several components that work together to provide a robust and scalable platform for container orchestration. These components are:

  1. Control Plane The control plane is the brains of the Kubernetes architecture. It manages the overall state of the cluster and controls the scheduling and deployment of containerized applications. The control plane consists of several components, including the API server, etcd, scheduler, and controller manager.

  2. Nodes: Nodes are the worker machines that run containerized applications. Each node runs a container runtime, such as Docker or containers, and is responsible for running and managing the containers.

  3. Pods: Pods are the smallest deployable units in Kubernetes. A pod consists of one or more containers that share the same network namespace and can communicate with each other using the localhost interface.

  4. Services: Services provide a stable IP address and DNS name for a set of pods. They enable communication between pods within the cluster and can also expose the pods to the outside world.

Learn About Kubernetes Concepts and Architecture

Installation :

Kubernetes can be installed using various tools, including Kubeadm. Kubeadm is a tool that automates the process of bootstrapping a Kubernetes cluster. In this section, we will cover the installation of Kubernetes using Kubeadm.

Prerequisites:

  • Three or more Ubuntu 18.04 servers with 2 CPU and 2GB RAM

  • Root or sudo access to all the servers

  • Docker installed on all servers

Step 1: Install Kubeadm and Kubernetes Components

sudo 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
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Step 2: Initialize the Cluster

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

Step 3: Configure kubectl

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

Step 4: Install Networking

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Step 5: Join the Nodes

kubeadm token create --print-join-command

Components:

In this section, we will cover some of the key components of Kubernetes.

  1. API Server: The API server is the central component of the Kubernetes control plane. It provides a RESTful API that enables users to interact with the cluster and manage the deployment, scaling, and management of containerized applications.

  2. etcd : etcd is a distributed key-value store that is used by Kubernetes to store the configuration data for the cluster. It is a highly available and fault-tolerant system that ensures that the cluster state is consistent across all nodes.

  3. Pods: A pod is the smallest deployable unit in Kubernetes. It is a logical host for one or more containers that share the same network namespace and can communicate with each other using the localhost interface. Pods can be created using YAML files, as shown below.

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: my-image
    ports:
    - containerPort: 80
  1. ReplicaSets: A ReplicaSet is responsible for ensuring that a specified number of pod replicas are running at any given time. It can be used to scale the number of replicas up or down based on the demand for the application. ReplicaSets can be created using YAML files, as shown below.
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-replicaset
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: my-image
        ports:
        - containerPort: 80
  1. Deployments: A Deployment manages the ReplicaSets and Pods in a declarative way. It allows you to create and update multiple replicas of an application in a rolling update fashion. Deployments can be created using YAML files, as shown below.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: my-image
        ports:
        - containerPort: 80
  1. Services: A Service is used to expose an application running inside a set of Pods to the outside world. It provides a stable IP address and DNS name for a set of Pods and can route traffic to the appropriate Pod based on the label selector. Services can be created using YAML files, as shown below.
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - name: http
    port: 80
    targetPort: 80
  type: LoadBalancer
  1. ConfigMaps: A ConfigMap is used to store configuration data in key-value pairs. It can be used to store environment variables, command-line arguments, and configuration files. ConfigMaps can be created using YAML files, as shown below.
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-configmap
data:
  DATABASE_URL: postgres://user:password@host:port/database
  1. Secrets: A Secret is used to store sensitive data, such as passwords, API keys, and TLS certificates. Secrets can be created using YAML files, as shown below.
apiVersion: v1
kind: Secret
metadata:
  name: my-secret
type: Opaque
data:
  username: YWRtaW4=
  password: MWYyZDFlMmU2N2Rm

Kubernetes Components | Kubernetes

Kubernetes Configuration File :

The Kubernetes configuration file is a YAML file that contains the specification for the desired state of the Kubernetes objects, such as pods, services, deployments, etc. It provides a declarative way of defining the desired state of the cluster, and Kubernetes ensures that the current state of the cluster matches the desired state specified in the configuration file.

Code Example:

yamlCopy codeapiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
    - name: nginx-container
      image: nginx

This code creates a pod named nginx-pod and a single container named nginx-container using the official nginx image.

generic my-secret --from-literal=password=secret-password

This command creates a secret named my-secret with a single data item password set to secret-password.

Configuration :

  1. Kubeadm Configuration File :

The Kubeadm configuration file is a YAML file that contains the specification for the desired state of the Kubernetes cluster. It provides a declarative way of defining the desired state of the cluster, and Kubeadm ensures that the current state of the cluster matches the desired state specified in the configuration file.

Code Example:

apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
nodeRegistration:
  kubeletExtraArgs:
    cloud-provider: aws
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
kubernetesVersion: "1.22.0"
controlPlaneEndpoint: "kubeapi.example.com:6443"
networking:
  podSubnet: "10.244.0.0/16"

This code creates an initialization configuration that sets cloud-provider to aws for kubelet, and a cluster configuration that sets the Kubernetes version to 1.22.0, the control plane endpoint to kubeapi.example.com:6443, and the pod subnet to 10.244.0.0/16.

  1. Kubeadm Configuration Management :

Kubeadm configuration management is the process of managing the configuration of the Kubernetes cluster using Kubeadm. Kubeadm provides several subcommands for managing the configuration, such as init, join, reset, etc.

Code Example using init subcommand:

sudo kubeadm init --config=kubeadm-config.yaml

This command initializes a Kubernetes cluster using the configuration specified in the kubeadm-config.yaml file.

Kubernetes - ConfigMaps - The IT Hollow

  1. Kubeadm Configuration Options :

Kubeadm provides several configuration options that can be used to customize the Kubernetes cluster, such as --kubernetes-version, --pod-network-cidr, --control-plane-endpoint, etc. These options can be specified on the command line or in the configuration file.

Code Example using --pod-network-cidr option:

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

This command initializes a Kubernetes cluster with the pod network CIDR set to 192.168.0.0/16.

  1. Kubeadm Configuration Secrets :

Kubeadm secrets are used to store sensitive information, such as certificates and keys. Secrets can be created and managed using the Kubeadm API or the kubectl command-line tool.

Code Example using --upload-certs option:

sudo kubeadm init --upload-certs

This command initializes a Kubernetes cluster and uploads the certificates to a Kubernetes secret.

  1. Kubeadm Configuration Best Practices :

Some best practices for Kubeadm configuration include using a version control system for the Kubeadm configuration file, separating configuration data from code, using consistent naming conventions, and using Kubeadm configuration options to customize the Kubernetes cluster.

Conclusion :

Kubernetes is a powerful open-source container orchestration platform that offers a robust architecture, flexible installation options, and a wide range of components for managing containerized applications at scale. Kubeadm is a popular tool for bootstrapping a Kubernetes cluster, offering a simple and easy-to-use interface for configuring and managing the cluster.

When working with Kubeadm, it's important to understand the key aspects of Kubernetes configuration, including the configuration file, configuration management, options, and secrets. Utilizing best practices such as version control for configuration files, consistent naming conventions, and separating configuration data from code can help ensure a smooth and efficient Kubernetes deployment.

By leveraging the features of Kubernetes and Kubeadm, developers and IT teams can benefit from a highly scalable and resilient infrastructure for their containerized applications, enabling faster deployment, better resource utilization, and improved application performance. With its community-driven development and continuous evolution, Kubernetes remains at the forefront of container orchestration technology, providing a powerful and flexible solution for modern application development and deployment.

480+ Devops Team Stock Photos, Pictures & Royalty-Free ...

Did you find this article valuable?

Support DevOpsculture by becoming a sponsor. Any amount is appreciated!