DevOps Classroomnotes 09/Jul/2022

Service Discovery

  • The service-discovery tools help solve the problem of finding which process are listening at which address.
  • Real discovery in k8s starts with a Service Object.
  • Service object is a way to create a named label selector

k8s Service

  • K8s service when created gets a cluster ip which is virtual in nature, when any other resource tries to access the service using cluster ip it forwards to request to one of the pod matching labels
    Preview
  • An easier way to create the service is by using kubectl expose
  • k8s service uses a label selecter which will find all the pods with matching labels and will load-balance across all the pods
  • since the cluster ip is virtual, its stable and it is appropriate to give it a DNS address.
  • k8s provides a DNS service exposed to Pods running in cluster.
  • Lets create a k8s service Refer Here for the changes
  • use kubectl to create and describe the service
    Preview
  • Create a test pod and try to access the service using curl command to check if the loadbalancing is happening or not
  • The full dns name for the service would be service-name.namespace.svc.cluster.local => nginx-svc.default.svc.cluster.local
  • Service should not forward the request to faulty pods, as this might impact application access, so lets see what can be done over here
    • Readiness Checks/Probes:
      • This is to check whether the application in container running in Pod is ready to serve requests or not
      • If this check fails the k8s removes the Ip address of Pods from all endpoints in Services
    • Liveness Checks/Probes:
      • This is to check whether or not application in container is running or not.
      • K8s restarts containers if this check fails based on restart policy
  • Refer Here for writing checks or probes
  • Refer Here for the sample probes
  • Accesing the service from outside cluster: For this in k8s service we have 3 options
    • Node Port: Where you expose service on some port of the node
    • Load Balancer Integration: Generally in all the managed clusters like AKS, EKS, GKE cluster is configured to integrate with external load balancers, so this can be used to expose the service
    • ExternalName: Will be a DNS record which you can add to existing DNS servers

Kubernetes Deployment

  • We know that Replicaset manage pods.
  • Deployment manages replica set.
  • K8s is a self-healing system. The top level deployment object manages replicaset, when you adjust number of replicas it will not match desired state so it will scale up or down
  • Deployment allows us to deploy the newer versions of the applications by ensuring it supports all the necessary options to minimize/make zero down time deployments and rollout to a new version or roll back to the older version.
  • Refer Here for the changeset & Refer Here for the fix for wrong indentation
    Preview
    Preview
    Preview
  • Now lets apply a new version (changing the container name to httpd)
  • Refer Here for the changes done
    Preview
  • To go back to the previous version
    Preview
    Preview
  • Deploy the new version with change reason. Refer Here
    Preview

Namespace

  • This is a virtual cluster. all the objects which we create are part of default namespace, but if we want we can create namespaces

Note:

  • To create k8s cluster in Azure we have created a linux vm and installed azure cli Refer Here
  • To create k8s in Azure Refer Here

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner