IT 3300 : Virtualization

Kubernetes Deployments

Labeling your resources in K8s

Labeling your resources can aid in administrative tasks.

  • Query using the label
    • kubectl get pods -l $label_name
  • Can apply labels to pods and services
    • kubect label pod $POD_NAME app=mypod
    • kubectl describe pods -l app=mypod

More Labeling Commands.

  • Can apply labels to services.
  • Can delete based on label
    • kubectl delete service -l foo=bar

A note about pods

You'll rarely create individual Pods directly in Kubernetes—even singleton Pods. This is because Pods are designed as relatively ephemeral, disposable entities. When a Pod gets created (directly by you, or indirectly by a controller), the new Pod is scheduled to run on a Node in your cluster. The Pod remains on that node until the Pod finishes execution, the Pod object is deleted, the Pod is evicted for lack of resources, or the node fails.

Better to use a deployment.

What is a deployment

  • A Deployment provides declarative updates for Pods
  • You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate.

Sample

  • kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
  • Run kubectl get deployments
    • DESIRED = how many we want
    • CURRENT = how many are running
    • UP-TO-DATE = how many replicas were changed to match desired state
    • AVAILABLE = how many are usable right now

How does this relate to pods?

Run kubectl get pods to look at what the deployment created.
Also, kubectl describe deployment.

Scaling

This is where we change the number of replicas of a deployment.

Scaling image 1

Scaling image 2

Scaling

  • Scaling out a Deployment will ensure new Pods are created and scheduled to Nodes with available resources. Scaling in will reduce the number of Pods to the new desired state.
  • If we run multiple instances of an APP, we then have to load-balance between them (services will inherently do this)
  • Services will also make sure that traffic is only sent to pods that are available.

Scaling

  • Scale to 4
    • kubectl scale deployments/nginx-deployment --replicas=4
    • Check deployments again.
  • Pods should have increased
    • kubectl get pods or
    • kubectl get pods -o wide
  • You can describe the deployments again to view event logs.
  • Make sure you can curl again.
    • As you run it, you should see that it pulls from different pod

Scaling

  • Scale down
    • kubectl scale deployments/nginx-deployment --replicas=2
    • Can even set to zero

Rolling update

  • Users expect applications to be available all the time and developers are expected to deploy new versions of them several times a day.
  • Look at image here

Rolling update

  • Promote an application from one environment to another (via container image updates)
  • Rollback to previous versions
  • Continuous Integration and Continuous Delivery of applications with zero downtime
  • Service only load balances to pods that are available.

A lot more stuff about deployments is found here