Skip to content

Write Kubernetes yaml file to deploy a sample app (You can use any publicly available app as deployment image) & make sure: - a. App is highly available. b. App/Pods can be updated in rollout manner.

License

Notifications You must be signed in to change notification settings

574n13y/Deploy-a-sample-app---Kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Deploy-a-sample-app---Kubernetes

Website

  • Write Kubernetes yaml file to deploy a sample app (You can use any publicly available app as deployment image) & make sure: a. App is highly available. b. App/Pods can be updated in rollout manner.

  • Signup to killercode

  • Login to Killercode kllrcode

  • install docker if not installed already

  • open vi write a kubernetes file.

    yaml
    # deployment.yaml
    
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: sample-app
    spec:
      replicas: 3  # Adjust the number of replicas based on your high availability requirements
      selector:
        matchLabels:
          app: sample-app
      template:
        metadata:
          labels:
            app: sample-app
         spec:
           containers:
            - name: sample-app
            image: nginx:latest  # Replace with your desired publicly available app image
            ports:
            - containerPort: 80
       strategy:
         rollingUpdate:
           maxSurge: 1
           maxUnavailable: 1
           type: RollingUpdate
    
    

Screenshot 2023-12-30 142721 Screenshot 2023-12-30 143144 Screenshot 2023-12-30 143215

 apt-get update
 kubectl get nodes
 kubectl version
  • This YAML file defines a Kubernetes Deployment with three replicas, ensuring high availability. The rollingUpdate strategy ensures that during a deployment update, only one new pod is created at a time (maxSurge: 1), and at least one old pod is available (maxUnavailable: 1), making the update process gradual and minimizing downtime.

  • Make sure to replace nginx:latest with the actual image of the publicly available app you want to deploy.

  • Apply the YAML file using the kubectl apply command:

    # bash
      kubectl apply -f deployment.yaml
    
  • This will create the deployment and the necessary pods for your sample app, ensuring high availability and supporting rolling updates. view kube details

  • deployments detail

     kubectl get deployments
    

    get deployment

  • get nodes

    kubectl get nodes
    

get nodes

  • describe deployment sample-app

     kubectl describe deployment sample-app
    

    describe deployment

  • describe pods

    kubectl describe pods
    

    describe pods describe pods 1 describe pods 2

  • describe pod and app

    kubectl get pods -l app=sample-app
    
  • describe pod apps 1,2,3

    kubectl describe pod sample-app-587d9c6687-2gk8r
    

    pod 1

    kubectl describe pod sample-app-587d9c6687-7cgft
    

    pod 2

    kubectl describe pod sample-app-587d9c6687-cxz4h
    

    pod 3

  • get pod app details get nodes

  • delete deployment delete

Deploy-a-sample-app via MiniKube on GCP

  • All the above process is same part from installation
  • install docker & minikube
  • install the latest minikube stable release on x86-64 Linux using Debian package: minikube
 curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
 sudo dpkg -i minikube_latest_amd64.deb

1

  • From a terminal with administrator access (but not logged in as root), run:
minikube start

2

  • Interact with your cluster

    kubectl get po -A
    

    3

    minikube kubectl -- get po -A
    

    4

    alias kubectl="minikube kubectl --"
    

    5

    minikube dashboard
    

    6 7

  • Deploy applications

  • Create a sample deployment and expose it on port 8080:

    kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0
    kubectl expose deployment hello-minikube --type=NodePort --port=8080
    
                 *OR(We have deployed two applications named as hello-minikubes & sample-app)*
    
  • open vi write a kubernetes file.

yaml
# deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample-app
spec:
  replicas: 3  # Adjust the number of replicas based on your high availability requirements
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
     spec:
       containers:
        - name: sample-app
        image: nginx:latest  # Replace with your desired publicly available app image
        ports:
        - containerPort: 80
   strategy:
     rollingUpdate:
       maxSurge: 1
       maxUnavailable: 1
       type: RollingUpdate

  • Let’s break each line down…
- apiVersion: Specifies the Kubernetes API version. In this case, it’s using the “apps/v1” API version, which is appropriate for Deployments.
- kind: Specifies the type of Kubernetes resource. Here, it’s “Deployment,” indicating that this configuration file is defining a Deployment.
- spec: This section defines the desired state of the Deployment.
- replicas: 3: Specifies that you want to run three replicas of your application.
- selector: Describes the selector to match pods managed by this Deployment.
- matchLabels: Specifies the labels that the Replica Set created by the Deployment should use to select the pods it manages. In this case, pods with the label app: sample-app are selected.
- template: Defines the pod template used for creating new pods.
- metadata: Contains the labels to apply to the pods created from this template. In this case, the pods will have the label
- app: sample-app.
- spec: Describes the specification of the pods.
- containers: This section specifies the containers to run in the pod.
- name: sample-app: Assigns a name to the container.
- image: example-image: Specifies the Docker image to use for this container.
- ports: Defines the ports to open in the container.
- containerPort: 8080: Indicates that the container will listen on port 80.
  • Apply the YAML file using the kubectl apply command:

    kubectl apply -f deployment.yaml
    

    8

  • It may take a moment, but your deployment will soon show up when you run:

    kubectl get services
    

    10 11 12 13 14 15

  • The easiest way to access this service is to let minikube launch a web browser for you:

    minikube service --all
    

    9

  • Validation 16

  • manage your cluster

  • Pause Kubernetes without impacting deployed applications:

    minikube pause
    
  • Unpause a paused instance:

    minikube unpause
    
  • Halt the cluster:/ stop

    minikube stop
    
    • Browse the catalog of easily installed Kubernetes services:
    minikube addons list
    
  • Create a second cluster running an older Kubernetes release:

    minikube start -p aged --kubernetes-version=v1.16.1
    
  • Delete Deployments - Delete all of the minikube clusters: 17

                                            ****
    

About

Write Kubernetes yaml file to deploy a sample app (You can use any publicly available app as deployment image) & make sure: - a. App is highly available. b. App/Pods can be updated in rollout manner.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published