Kubernetes concepts and instantiation

Category : Kubernetes | Sub Category : Kubernetes With Java | By Prasad Bonam Last updated: 2023-11-21 10:46:33 Viewed : 235


Kubernetes is a powerful open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Here are some key concepts in Kubernetes and an overview of how to instantiate or deploy applications in a Kubernetes cluster:

Key Kubernetes Concepts:

  1. Nodes:

    • Nodes are the individual machines (physical or virtual) that make up the Kubernetes cluster.
    • Each node runs a container runtime (like Docker) and components necessary to communicate with the master and manage containers.
  2. Pods:

    • The smallest deployable units in Kubernetes.
    • A pod can contain one or more containers that are tightly coupled and share the same network namespace, storage, and specifications.
    • Containers within a pod can communicate with each other using localhost.
  3. ReplicaSet:

    • Ensures that a specified number of replicas (instances) of a pod are running at all times.
    • Helps with scaling and ensuring high availability.
  4. Deployment:

    • Provides declarative updates to applications, allowing you to describe the desired state for your deployed containers.
    • Manages the deployment and scaling of a set of pods.
  5. Service:

    • An abstraction that defines a logical set of pods and a policy by which to access them.
    • Enables communication between different parts of an application, or between applications.
  6. Namespace:

    • A way to divide cluster resources between multiple users (via resource quotas) or between multiple projects or teams.
    • Provides a scope for names. Names of resources need to be unique within a namespace.
  7. ConfigMap and Secret:

    • ConfigMap holds configuration data as key-value pairs.
    • Secret holds sensitive information, such as passwords or API keys.

Kubernetes Instantiation (Deployment Example):

To deploy an application in Kubernetes, you typically define resources using YAML manifests and apply them to the cluster. Here is a simple example:

  1. Create a Deployment YAML file (deployment.yaml):

    yaml
    apiVersion: apps/v1 kind: Deployment metadata: name: my-app-deployment spec: replicas: 3 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-app-container image: your-image-name:tag ports: - containerPort: 8080

    Replace your-image-name:tag with the actual name and tag of your Docker image.

  2. Apply the Deployment to the Cluster:

    bash
    kubectl apply -f deployment.yaml

    This command creates the deployment, and Kubernetes ensures that three instances of your application are running.

  3. Expose the Deployment as a Service (service.yaml):

    yaml
    apiVersion: v1 kind: Service metadata: name: my-app-service spec: selector: app: my-app ports: - protocol: TCP port: 80 targetPort: 8080 type: LoadBalancer
  4. Apply the Service to the Cluster:

    bash
    kubectl apply -f service.yaml

    This command creates a service that exposes your application to the external world.

After applying these manifests, Kubernetes will manage the deployment and scaling of your application, ensuring high availability and providing access to the service. You can monitor the status and logs of your pods using kubectl commands.

Search
Related Articles

Leave a Comment: