Kubernetes Implementation using YAML

                             Example of implementing Kubernetes using a YAML file. 

                                                  



Let's create a simple deployment for a web application.


1. Create a file named `webapp-deployment.yaml` and open it in a text editor.


2. Add the following content to the file:


```yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: webapp-deployment

spec:

  replicas: 3

  selector:

    matchLabels:

      app: webapp

  template:

    metadata:

      labels:

        app: webapp

    spec:

      containers:

        - name: webapp-container

          image: nginx:latest

          ports:

            - containerPort: 80

```


Let's break down the YAML file:


- `apiVersion`: Specifies the version of the Kubernetes API being used. In this case, we're using `apps/v1`.


- `kind`: Defines the type of Kubernetes resource we're creating, which is a `Deployment`.


- `metadata`: Contains metadata about the deployment, such as its name.


- `spec`: Specifies the desired state of the deployment.


  - `replicas`: Defines the number of replicas (instances) of the application to be created.


  - `selector`: Defines the labels used to identify the pods managed by this deployment.


  - `template`: Specifies the template for creating the pods.


    - `metadata`: Contains labels that will be applied to the pods.


    - `spec`: Specifies the specification for the containers in the pod.


      - `containers`: Defines the containers to be created within the pod.


        - `name`: Specifies the name of the container.


        - `image`: Specifies the container image to be used. In this example, we're using the latest version of the Nginx web server.


        - `ports`: Defines the port to be exposed by the container.


3. Save the `webapp-deployment.yaml` file.


4. To create the deployment, open a terminal or command prompt, navigate to the directory where the YAML file is located, and run the following command:


```shell

kubectl apply -f webapp-deployment.yaml

```


This command instructs Kubernetes to apply the configuration defined in the YAML file.


Kubernetes will create a deployment named `webapp-deployment` with three replicas of the Nginx web server. The pods created by the deployment will be labeled with `app=webapp`. The deployment ensures that the desired number of replicas is maintained and manages the lifecycle of the pods.


You can check the status of the deployment by running the following command:


```shell

kubectl get deployments

```


This will display information about the deployed application, including the number of replicas, available replicas, and desired replicas.


That's it! You have successfully created a basic Kubernetes deployment using a YAML file. You can further explore Kubernetes concepts and YAML specifications to define more complex configurations and manage various aspects of your applications.

Comments

Popular posts from this blog

Data Analytics - Overview

New Energy Solutions - Overview

Docker - Overview