Show List

Kubernetes Architecture

Kubernetes architecture consists of several key components that work together to manage containerized applications and services. These components include:

  • Master node: The master node is responsible for managing the Kubernetes cluster and its various components. It runs the Kubernetes API server, controller manager, and etcd (a distributed key-value store that is used to store configuration data).
  • Worker nodes: Worker nodes are where containerized applications are run. Each worker node runs a container runtime (such as Docker) and a Kubernetes component called kubelet, which communicates with the master node to manage the containers running on that node.
  • Pods: Pods are the smallest deployable units in Kubernetes and are used to encapsulate one or more containers. Each pod has its own IP address and can be used to host a single application or multiple co-located applications.
  • Services: Services provide a way to expose pods to the network and allow them to communicate with each other. They are used to abstract the network details away from the pods, and provide a stable IP address and DNS name for accessing the pod.
  • Controllers: Controllers are used to manage the desired state of the pods and ensure that the actual state of the cluster matches the desired state. There are several types of controllers, including ReplicaSets, Deployments, and StatefulSets, each with its own specific use case.

Here are some examples of how these components can be used in Kubernetes:

  • Pod example:
yaml
Copy code
apiVersion: v1 kind: Pod metadata: name: myapp-pod spec: containers: - name: myapp-container image: myapp-image:latest ports: - containerPort: 80

This YAML file defines a single pod named "myapp-pod" that contains a single container named "myapp-container". The container runs the image "myapp-image:latest" and exposes port 80.

  • Service example:
yaml
Copy code
apiVersion: v1 kind: Service metadata: name: myapp-service spec: selector: app: myapp ports: - protocol: TCP port: 80 targetPort: 80 type: LoadBalancer

This YAML file defines a service named "myapp-service" that exposes the pods with the label "app=myapp" on port 80. The service is of type "LoadBalancer", which means that an external load balancer will be created to route traffic to the pods.

  • Controller example:
yaml
Copy code
apiVersion: apps/v1 kind: Deployment metadata: name: myapp-deployment spec: replicas: 3 selector: matchLabels: app: myapp template: metadata: labels: app: myapp spec: containers: - name: myapp-container image: myapp-image:latest ports: - containerPort: 80

This YAML file defines a deployment named "myapp-deployment" that creates and manages three replicas of the pod template specified in the "template" section. The deployment uses a label selector to match the pods with the label "app=myapp". If any of the pods go down, the deployment controller will automatically spin up a new pod to maintain the desired state of three replicas.


    Leave a Comment


  • captcha text