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.ai

Roost.ai is an Ephemeral Environments Platform for engineering teams that creates, manages and deploys DevOps environments. It replaces static and shared staging environments while automating labor-intensive development processes and testing. The platform removes the complexity of managing cloud-native infrastructure and shortens release cycles by eliminating custom script creation and wait times for testing and review cycles.

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...

How Ephemeral Environments Works with Infrastructure as Code (IaC)
How Ephemeral Environments Works with Infrastructure as Code (IaC)
October 22, 2021

The Roost platform on-demand creates an ephemeral environment to test each and every change and release it to production...

Environment management a top challenge for companies using Kubernetes
Environment management a top challenge for companies using Kubernetes
October 22, 2021

According to Gartner® research, "By 2025, multicluster management and security will emerge as top challenges for organiz...