DevOps Classroomnotes 16/Sep/2023

Managed Kubernetes or Kubernetes as a Service

  • Managed Kuberenetes (Kubernetes as a Service) is the offerings from various cloud providers.
  • In these Control-Plane is managed by Cloud Service Providers and they charge you hourly for that
  • For worker nodes, storage and other resources charges are as usual.
  • Popular Kuberentes offerings
    • AKS (Azure Kubernetes Services)
    • EKS (Elastic Kuberentes Services)
    • GKE (Google Kubernetes Engine)

AKS

  • Install kubectl in your system
choco install kubernetes-cli
# mac
brew install kubectl

Activity: Create a replica set

  • Apply the replicaset
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx-rs
  labels:
    app: nginx
    purpose: svcdemo
spec:
  replicas: 3
  minReadySeconds: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginxc
          image: nginx:1.25
          ports:
            - containerPort: 80
              protocol: TCP
          env:
            - name: purpose
              value: learning
            - name: why
              value: dontknow

Preview
* Refer Here for the changes that include adding environmental variables in the container
Preview

  • Lets create the service and expose it using the LoadBalancer. Azure internally takes request from cloud controller manager and creates a Load Balancer and all the necessary rules to expose the nginx service on Azure Load Balancer
  • Apply the service
    Preview
  • We get the external ip which represents the ipaddress of the loadbalancer. Now access by using http://<lb-ip>:<port>
    Preview
  • Refer Here for the changeset
  • Exercise:

    • Write a spec to expose jenkins/jenkins which runs on 8080 port using nodePort on Port 30001
    • DNS:
      • A record
      • CName Record
  • Service with external name
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc-external
  labels:
    app: nginx
    purpose: svcdemo
spec:
  type: ExternalName
  externalName: nginx.qt.com
  selector:
    app: nginx

Deployments

  • Refer Here for the official docs
  • Overview
    Preview
  • Deployment is a workload which creates
    • Replica Sets: These create
      • Pods: Which inturn creates
        • Containers: This is where the applcation runs
          Preview
  • Kubernetes Deployments creates Replicaset which can be persisted which helps us in performing rolling updates and rollbacks
  • Lets create a basic template for deployment of nopCommerce. The image will be shaikkhajaibrahim/nopcommerceaug23
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nop-deploy
spec:
  minReadySeconds: 5
  replicas: 4
  selector:
    matchLabels:
      app: nop
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  template:
    metadata:
      labels:
        app: nop
        version: v1.1
    spec:
      containers:
        - name: nop
          image: shaikkhajaibrahim/nopcommerceaug23
          ports:
            - containerPort: 80
              protocol: TCP
  • Apply the deployment and check the objects
    Preview

Performing Rolling updates and Rollback using Deployments

  • Lets create a k8s manifest to deploy an application shaikkhajaibrahim/deploy-sample
  • Lets create with 10 replicas and a service exposed via loadbalancer
  • Refer Here for the changes done
  • Apply the deployment and set the current namespace to prod
 kubectl config set-context --current --namespace=prod
  • Now create service
    Preview
  • Access the application
    Preview
  • Now we have some extra commands
    Preview
  • Annotation: Refer Here
  • We will be adding an annotation to add change cause kubernetes.io/change-cause
  • apply the deployment Refer Here for changes
    Preview
  • Lets rollback to revision 1
    Preview

Health Checks in Kubernetes

  • Types of HealthChecks
    Preview
  • Probe Types
    • Exec
    • TCP
    • HTTP
    • GRPC
  • Lets write liveness, readiness probes in the deployment spec
  • Probes are written as part of container spec
  • Refer Here for a sample

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube