What is Kubernetes?

Kubernetes, a "Container Orchestration Platform", that runs container workloads efficiently in a distributed environment. Application workloads are defined as microservices or macroservices that run in an isolated environment and interact with other services.


#1 Use Service

Pods are the smallest deployable units of computing that can be created and managed in Kubernetes.

Application runs inside pod in a container. As Kubernetes assigns internal IP Address to each pod, all deployed applications can easily communicate over Pod IP within the cluster.

However, pods may be rescheduled in case of failures that leads to a new IP assignment. So relying on Pod IP for application networking is not preferred.

Service acts as an internal Load Balancer to the pods defined within. Service enables pod discovery and traffic routing. Now application can communicate with the service over ClusterIP without worrying about Pod IP.

 

#2 Define container resource limit

Always define container resource limits as per expected application's footprint. Computing resources are CPU and Memory. Missing limit declaration may exhaust entire node resource and may lead running pod eviction.

 

#3 Handle errors gracefully

Application should handle the errors gracefully instead of an abrupt exit. Kubernetes will restart terminated containers repeatedly unless pod restartPolicy is set to "Never".

 

blog-kubernetes made easy

 

 

foo.yaml : Create a foo-pod with two containers. One container can be your main application and another container may be supporting application to the main application (or sidecar).

apiVersion: v1
kind: Pod
metadata:
   name: foo
   labels:
      app: foo-lab
spec:
   containers:
   - name: foss
     image: foss:v1
     resources:
        limits:
        memory: "128Mi"
        cpu: "200m"
    ports:
    - name: foss
         containerPort: 8080
    - name: fox
      image: fox:v1
      resources:
        limits:
        memory: "128Mi"
        cpu: "200m"
    ports:
      - name: fox
      containerPort: 8081

 

foo-service.yaml: Create foo-services with two ports to point two different ports exposed by the foo-pod.

apiVersion: v1
kind: Service
metadata:
   name: foo-service
spec:
  selector:
app: foo-lab
  ports:
  - name: foss-tcp
    port: 80
    targetPort: 8080
  - name: fox-tcp
    port: 81
    targetPort: 8081

 

bar.yaml: Create a bar-pod and use environment variable to point foo-service.

apiVersion: v1
kind: Pod
metadata:
  name: bar
  labels:
    app: bar-lab
spec:
 containers:
 - name: bar
   image: bar:v1
   env:
   - name: FOSS_SERVICE
     value: foo-service:80
   - name: FOX_SERVICE
      value: foo-service:81
   resources:
     limits:
        memory: "128Mi"
       cpu: "200m"
   ports:
     - name: bar-port
       containerPort: 8080

Roost helps us address cost issues by providing capabilities that allow our team and users to control the amount of time a cluster runs... Early results reveal cluster run-time savings over 80% from our previous environment.

CTO, Enterprise Security Company

ABOUT ROOST

Roost is an “Environments as a Service” platform that creates instant and ephemeral environments which automatically validates applications allowing developers to spot potential errors before a pull request is merged to the CD pipeline for release. We believe that reducing the distance between development and production is a way to simultaneously improve development velocity and pull request merge success.

 

 

Mayank Gaikwad

About Mayank Gaikwad

Mayank has over a decade of experience in Software Development and DevOps Engineering and is a member of Roost's technical staff.

Please Share this Blog

You may find these blog posts of interest too.

How to use Event Framework for Complex Test Environments
How to use Event Framework for Complex Test Environments
October 22, 2021

With the increasing number of services in cloud-native applications and their dependence on various third-party applicat...

Accelerate Software Delivery Releases - Eliminate Staging Environment
Accelerate Software Delivery Releases - Eliminate Staging Environment
October 22, 2021

Current Testing and Staging Processes are Slow & Cumbersome Current DevOps pipelines have multiple test environments...

Remove friction between product managers and dev by using preview URLs
Remove friction between product managers and dev by using preview URLs
October 22, 2021

What captivated me about Heisenberg's Uncertainty Principle, was not just the principle itself, but its fundamental natu...