Kubernetes Devops

April 14, 2022

What is DevOps and How is it Related to Kubernetes?

DevOps bridges the gap between development and operations teams that previously operated independently of each other in separate silos. DevOps unifies the processes and workflows of development and operations, providing a shared infrastructure and toolchain, organized around the concept of pipelines. It is a collaborative approach in which each team learns about the processes used by other teams, allowing them to work together to improve quality and efficiency.

As organizations adopted DevOps, development teams built their pipelines using multiple tools, and had to customize and integrate them. Whenever a new tool was added or a new requirement introduced, the pipeline had to be rebuilt. This was inefficient, and the solution was to bundle pipeline components in containers and manage them with Kubernetes

A container is a unit of software that packages all the code and dependencies needed to run an application or service in any software environment. By creating a modular infrastructure based on microservices running in containers, organizations can create flexible, portable pipelines, which can be set up and duplicated with low effort. A container orchestrator like Kubernetes helps manage a large number of containers as part of a cluster, automating many aspects of their lifecycle.

In this article:

How Kubernetes is Transforming Infrastructure

Kubernetes is the most popular container orchestration platform, and has become an essential tool for DevOps teams. Application teams can now deploy containerized applications to Kubernetes clusters, which can run either on-premises or in a cloud environment. 

The use of containers and Kubernetes ensures that applications and infrastructure always deploy and behave the same way, due to immutability. Kubernetes provides infrastructure abstraction that completely automates deployment and provisioning, eliminating the need for configuration of individual software components.

Kubernetes creates a clear separation between operating runtime infrastructure and deploying applications. IT staff can focus on managing Kubernetes clusters and addressing issues like capacity management, infrastructure monitoring, disaster recovery, networking, and security. Application teams can focus on building container images, deploying and configuring Kubernetes manifest YAML, and managing secrets.

A Kubernetes infrastructure eases the burden on both operations and application teams and improves collaboration. Instead of having to coordinate between multiple stakeholders to get an environment launched or an application deployed, all this can be done from a shared, declarative configuration.

Related content: Read our guide to Kubernetes architecture

Kubernetes as an Enabler for Enterprise DevOps

Kubernetes has many features that help DevOps teams build large-scale pipelines. Its main value is that it can automate the manual tasks required for orchestration. Here are a few ways Kubernetes powers enterprise DevOps.

Infrastructure and Configuration as Code

Kubernetes lets you build your entire infrastructure as code (a pattern known as IaC). Kubernetes can define and automatically provision all aspects of your applications and tools, including access control, networking, databases, storage, and security. 

You can similarly manage environment configuration in code. Instead of running a script every time you need to deploy a new environment, you prepare a source repository with environment configuration, and Kubernetes and use this declarative configuration to set up environments automatically.

You can also use a version control system to manage your code like an application under development. This allows teams to easily define and modify infrastructure and configurations, and push changes to Kubernetes for automated processing.

Cross-functional Collaboration

Kubernetes enables fine-grained access control over elements of your pipeline. You can specify that certain roles or applications can perform certain tasks and block access to other roles or applications. For example, you can limit customers to view only production instances of the application, while developers and testers work on development instances, within the same cluster.

This type of control promotes seamless collaboration while maintaining configuration and resource consistency. 

On-demand Infrastructure

Kubernetes allows developers to create infrastructure on a self-service basis. Cluster administrators set up standard resources, such as persistent volumes, and developers can provision them dynamically based on their requirements, without having to contact IT. Operations teams retain full control over the type of resources available on the cluster, resource allocation, and security configuration.

Zero Downtime Deployments

Rolling updates and automatic rollbacks in Kubernetes allow teams to deploy new versions without downtime. You can use Kubernetes to switch traffic between services, and update application instances one at a time without interrupting production, and without having to redeploy the entire environment.

These features enable progressive deployment patterns like blue/green deployment, canary deployments, and A/B testing.

6 Kubernetes CI/CD Best Practices

The following best practices can help you make the most of CI/CD in a Kubernetes environment.

Implement Git-based Workflows (GitOps)

Triggering CI/CD pipelines through Git-based operations has many advantages in terms of consistency and development productivity. Organizations keep all pipeline and environment changes in a single source repository, allowing developers to carefully review changes and know exactly what is deployed at any point in time. GitOps always makes it much easier to rollback to a previous good configuration in case of problems in production.

Related content: Read our guide to GitOps vs. DevOps (coming soon)

Leverage Blue/Green or Canary Deployment Patterns

The CI/CD pipeline deploys the code to production after it passes automated tests. However, tests are not perfect and it is common to find bugs or even security issues in a production environment.

The blue/green deployment pattern can address this problem. A green deployment means you deploy a second set of application instances in parallel to the production instances. You switch users over to the new version, but keep the old version running for easy rollback in case of issues.

The canary deployment pattern is another way to reduce the risk of new deployments. A canary deployment is an upgraded version of an application which is served to a small percentage of users to test for errors and observe end-user metrics. If the new version is well received by users, it is served to additional users, until eventually all users see the new version. If any problem is discovered, all users are switched back to the current stable version.

Kubernetes clusters use services to manage canary deployments. A service can use labels and selectors to route traffic to specific pods. This way, a certain fraction of users can be rerouted to pods running a canary version of the application.

Release the Same Container that Was Tested

Immutable containers deployed in staging, development, or QA environments should be identical to containers deployed in production. This process avoids changes that can occur between successful testing and actual product launch. To do this, use a Git tag to trigger a deployment to production and deploy the container with the tag’s commit ID.

Keep Secrets Secure

Secrets are digital credentials that must be protected within a Kubernetes cluster. Most applications use secrets to enable authentication with CI/CD services and applications. Source control systems like GitHub can expose secrets if they are included in the code in plaintext, resulting in severe security risks. Therefore, you must ensure secrets are safely stored and encrypted outside the container, in a dedicated secrets management system or using Kubernetes secrets objects.

Scan Container Images for Vulnerabilities

Scanning and testing all new container images is important to identify vulnerabilities introduced by new builds or components. Remember that every new build in your CI/CD pipeline can potentially introduce new vulnerabilities. It is also important to test container images to ensure that containers have the expected content and that image specifications are correctly defined.

Leverage IaC Scanning

Infrastructure as a Service (IaC) allows teams to automatically configure IT infrastructure. Infrastructure automation has become a critical part of modern DevOps processes. Kubernetes YAML files and Helm charts are a special case of IaC configuration templates.

The wide use of IaC creates new security risks, because a single IaC template (for example, a Kubernetes pod specification) can be used to create a large number of runtime resources. Any vulnerability in the underlying template will be inherited by all resources. And so IaC templates represent a new attack surface.

An IaC scanning tool analyzes common cloud-native formats such as Dockerfiles and Kubernetes YAML and applies a set of rules that enforce good security practices. They can also suggest additional ways to harden Kubernetes configurations.

For example, IaC scanning can detect Docker images designed to run as root, Kubernetes manifests requesting privileged access to a node’s file system, or scripts that set up publicly exposed Amazon S3 buckets. Another important capability of IaC scanners is that they can find secrets included in plaintext within IaC templates.

It is important to use IaC scanning tools when initially authoring configurations, and on an ongoing basis as part of automated testing conducted throughout the CI/CD pipeline.