↓ Skip to main content
Kubernetes

Deployments: K8S

·1 min
Table of Contents

A declarative way of maintaining the desired state.

Continuing my example from the last blog

--- # Pod deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-server-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-go-server
  template:
    metadata:
      labels:
        app: my-go-server
    spec:
      containers:
        - name: go-server
          image: samarthya/epserver:2.0
          resources:
            limits:
              memory: "256Mi"
              cpu: "1024m"
          env:
            - name: SERVERPORT
              value: "9090"
          ports:
            - containerPort: 9090
# Reference - https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

In my deployment, I have two replicas configured, which can be increased to three using the command like the one below.

k scale deployment/go-server-deployment --replicas=3

If I wish rollout a change for all pods, which can be conveniently managed via deployments it is as easy as issuing a single command.

k set image deployment/go-server-deployment go-server=samarthya/epserver:1.0 --record=true

History is also maintained

k rollout history deployment go-server-deployment 
REVISION  CHANGE-CAUSE
1         <none>
2         k set image deployment/go-server-deployment go-server=samarthya/epserver:2.0 --record=true

Other command that you can issue for rollout are as under

Available Commands:
  history     View rollout history
  pause       Mark the provided resource as paused
  restart     Restart a resource
  resume      Resume a paused resource
  status      Show the status of the rollout
  undo        Undo a previous rollout
k rollout undo

References
#

Author
Samarthya
Engineer, learner, tinkerer. This is my trophy shelf of everyday work and leisure.

Related

NetworkPolicy: K8S

·2 mins
How can a pod communicate with the other pod? The answer to this question is through a network policy. Network Policy is a specification of how groups of pods are allowed to communicate with each other and other network endpoints.

Probes: K8S

·5 mins
In this blog we will be talking about Liveness, Readiness and Startup probes of a container. A Service in Kubernetes is an abstraction which defines a logical set of Pods and a policy by which to access them. — - Life without a service What is Kubelet? # Kubelet is a primary node agent that runs on every node. Works in term of PodSpec, that describes a POD (JSON or Yaml). Liveness Probe # It is used by kubelet to decide when to restart the container. periodSeconds defines when the kubelet check periodically. initialDelaySeconds specifies the initial wait before checking. I just created a single container pod that will run touch command to create a file and then it deletes that specific file after a delay, on which the livenessProbe is listening on and then once liveness fails we can check the container.

Services: K8S

·3 mins
There are multiple Kubernetes objects we will be talking about in this blog. Mainly Services, Selectors and Labels. Service is an abstraction which defines a logical set of Pods and a policy by which to access them. A Service in Kubernetes is a REST object, similar to a Pod. Service tags the pods, logically grouping them using selectors. Pods have a lifecycle, they are born, they live, process and then they die. The pods (desired state) can be managed using deployment. A label is an identifying attribute of an object, and can be defined at the creation time, and subsequently modified and added at any time. Label selector is a grouping primitive in Kubernetes and allows client/user to identify a set of objects. There are two sets of selectors equality-based and set-based. An abstract way to expose an application running on a set of Pods as a network service. The set of Pods targeted by a Service is usually determined by a selector.