Introduction to Day 2 Kubernetes
Tags: aws, devops, kubernetes, design
Published: 2023-04-24 16:08:45

Over the years, I have shared several blog posts about Kubernetes ([What are Containers and Kubernetes](https://eyal-estrin.medium.com/what-are-containers-and-kubernetes-b20137d7c97), [Modern Cloud deployment and usage](https://dev.to/aws-builders/modern-cloud-deployment-and-usage-491l), [Introduction to Container Operating Systems](https://dev.to/aws-builders/introduction-to-container-operating-systems-49o8), and more).  
Kubernetes became a de-facto standard for running container-based workloads (for both on-premise and the public cloud), but most organizations tend to fail on what is referred to as Day 2 Kubernetes operations.  
In this blog post, I will review what it means "Day 2 Kubernetes" and how to prepare your workloads for the challenges of Day 2 operations.  
## Ready, Set, Go!
In the software lifecycle, or the context of this post, the Kubernetes lifecycle, there are several distinct stages:  
### Day 0 - Planning and Design
In this stage, we focus on designing our solution (application and underlying infrastructure), understanding business needs, budget, required skills, and more.  
For the context of this post, let us assume we have decided to build a cloud-native application, made of containers, deployed on top of Kubernetes.  
### Day 1 - Configuration and Deployment
In this stage, we focus on deploying our application using the Kubernetes orchestrator and setting up the configurations (number of replicas, public ports, auto-scale settings, and more).  
Most organizations taking their first steps deploying applications on Kubernetes are stacked at this stage.  
They may have multiple environments (such as Dev, Test, UAT) and perhaps even production workloads, but they are still on Day 1.  
### Day 2 - Operations
Mature organizations have reached this stage.  
This is about ongoing maintenance, observability, and continuous improvement of security aspects of production workloads.  
In this blog post, I will dive into "Day 2 Kubernetes".  
## Day 2 Kubernetes challenges
Below are the most common Kubernetes challenges:  

### Observability
Managing Kubernetes at a large scale requires insights into the Kubernetes cluster(s).  
It is not enough to monitor the Kubernetes cluster by collecting performance logs, errors, or configuration changes (such as Nodes, Pods, containers, etc.)  
We need to have the ability to truly understand the internals of the Kubernetes cluster (from logs, metrics, etc.), be able to diagnose the behavior of the Kubernetes cluster – not just performance issues, but also debug problems, detect anomalies, and (hopefully) be able to anticipate problems before they affect customers.  
Prefer to use cloud-native monitoring and observability tools to monitor Kubernetes clusters.  
Without proper observability, we will not be able to do root cause analysis and understand problems with our Kubernetes cluster or with our application deployed on top of Kubernetes.  
Common tools for observability:  
* [Prometheus](https://prometheus.io/docs/introduction/overview/) - An open-source systems monitoring and alerting toolkit for monitoring large cloud-native deployments.  
* [Grafana](https://grafana.com/docs/grafana/latest/introduction/) - An open-source query, visualization, and alerting tool (resource usage, built-in and customized metrics, alerts, dashboards, log correlation, etc.)  
* [OpenTelemetry](https://opentelemetry.io/) - A collection of open-source tools for collecting and exporting telemetry data (metrics, logs, and traces) for analyzing software performance and behavior.  

#### Additional references for managed services:
* [Amazon Managed Grafana](https://docs.aws.amazon.com/grafana/latest/userguide/getting-started-with-AMG.html)  
* [Amazon Managed Service for Prometheus](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-getting-started.html)  
* [AWS Distro for OpenTelemetry](https://aws.amazon.com/otel/faqs/)  

### Security and Governance
On the one hand, it is easy to deploy a Kubernetes cluster in private mode, meaning, the API server or the Pods are on an internal subnet and not directly exposed to customers.  
On the other hand, many challenges in the security domain need to be solved:  
* Secrets Management – A central and secure vault for generating, storing, retrieving, rotating, and eventually revoking secrets (instead of hard-coded static credentials inside our code or configuration files).  
* Access control mechanisms – Ability to control what persona (either human or service account) has access to which resources inside the Kubernetes cluster and to take what actions, using RBAC (Role-based access control) mechanisms.  
* Software vulnerabilities – Any vulnerabilities related to code – from programming languages (such as Java, PHP, .NET, NodeJS, etc.), use of open-source libraries with known vulnerabilities, to vulnerabilities inside Infrastructure-as-Code (such as Terraform modules)  
* Hardening – Ability to deploy a Kubernetes cluster at scale, using secured configuration, such as CIS Benchmarks.  
* Networking – Ability to set isolation between different Kubernetes clusters or even between different development teams using the same cluster, not to mention multi-tenancy where using the same Kubernetes platform to serve different customers.  

#### Additional References:
* [Securing the Software Supply Chain in the Cloud](https://dev.to/aws-builders/securing-the-software-supply-chain-in-the-cloud-3p1h)  
* [OPA (Open Policy Agent) Gatekeeper](https://open-policy-agent.github.io/gatekeeper/website/docs/)  
* [Kyverno - Kubernetes Native Policy Management](https://kyverno.io/)  
* [Foundational Cloud Security with CIS Benchmarks](https://www.cisecurity.org/insights/blog/foundational-cloud-security-with-cis-benchmarks)  
* [Amazon EKS Best Practices Guide for Security](https://aws.github.io/aws-eks-best-practices/security/docs/)  

### Developers experience
Mature organizations have already embraced DevOps methodologies for pushing code through a CI/CD pipeline.  
The entire process needs to be done automatically and without direct access of developers to production environments (for this purpose you build break-glass mechanisms for the SRE teams).  
The switch to applications wrapped inside containers, allowed developers to develop locally or in the cloud and push new versions of their code to various environments (such as Dev, Test, and Prod).  
Integration of CI/CD pipeline, together with containers, allows organizations to continuously develop new software versions, but it requires expanding the knowledge of developers using training.  
The use of [GitOps](https://www.cncf.io/blog/2021/09/28/gitops-101-whats-it-all-about/) and tools such as [Argo CD](https://argo-cd.readthedocs.io/en/stable/#what-is-argo-cd) allowed a continuous delivery process for Kubernetes environments.  
To allow developers, the best experience, you need to integrate the CI/CD process into the development environment, allowing the development team the same experience as developing any other application, as they used to do in the on-premise for legacy applications, which can speed the developer onboarding process.  

#### Additional References:
* [GitOps 101: What is it all about?](https://www.cncf.io/blog/2021/09/28/gitops-101-whats-it-all-about/)  
* [Argo CD - Declarative GitOps CD for Kubernetes](https://argo-cd.readthedocs.io/en/stable/)  
* [Continuous Deployment and GitOps delivery with Amazon EKS Blueprints and ArgoCD](https://aws.amazon.com/blogs/containers/continuous-deployment-and-gitops-delivery-with-amazon-eks-blueprints-and-argocd/)  

### Storage
Any Kubernetes cluster requires persistent storage - whether organizations choose to begin with an on-premise Kubernetes cluster and migrate to the public cloud, or provision a Kubernetes cluster using a managed service in the cloud.  
Kubernetes supports multiple types of persistent storage – from object storage (such as [Azure Blob storage](https://github.com/kubernetes-sigs/blob-csi-driver) or [Google Cloud Storage](https://github.com/ofek/csi-gcs)), block storage (such as [Amazon EBS](https://github.com/kubernetes-sigs/aws-ebs-csi-driver), [Azure Disk](https://github.com/kubernetes-sigs/azuredisk-csi-driver), or [Google Persistent Disk](https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver)), or file sharing storage (such as [Amazon EFS](https://github.com/aws/aws-efs-csi-driver), [Azure Files](https://github.com/kubernetes-sigs/azurefile-csi-driver) or [Google Cloud Filestore](https://github.com/kubernetes-sigs/gcp-filestore-csi-driver)).  
The fact that each cloud provider has its implementation of persistent storage adds to the complexity of storage management, not to mention a scenario where an organization is provisioning Kubernetes clusters over several cloud providers.  
To succeed in managing Kubernetes clusters over a long period, knowing which storage type to use for each scenario, requires storage expertise.  

### High Availability
High availability is a common requirement for any production workload.  
The fact that we need to maintain multiple Kubernetes clusters (for example one cluster per environment such as Dev, Test, and Prod) and sometimes on top of multiple cloud providers, make things challenging.  
We need to design in advance where to provision our cluster(s), thinking about constraints such as multiple availability zones, and sometimes thinking about how to provision multiple Kubernetes clusters in different regions, while keeping HA requirements, configurations, secrets management, and more.  
Designing and maintaining HA in Kubernetes clusters requires a deep understanding of Kubernetes internals, combined with knowledge about specific cloud providers' Kubernetes management plane.  

#### Additional References:
* [Designing Production Workloads in the Cloud](https://dev.to/aws-builders/designing-production-workloads-in-the-cloud-4ff0)  
* [Amazon EKS Best Practices Guide for Reliability](https://aws.github.io/aws-eks-best-practices/reliability/docs/)  

### Cost optimization
Cost is an important factor in managing environments in the cloud.  
It can be very challenging to design and maintain multiple Kubernetes clusters while trying to optimize costs.  
To monitor cost, we need to deploy cost management tools (either the basic services provided by the cloud provider) or third-party dedicated cost management tools.  
For each Kubernetes cluster, we need to decide on node instance size (amount of CPU/Memory), and over time, we need to review the node utilization and try to right-size the instance type.  
For non-production clusters (such as Dev or Test), we need to understand from the cloud vendor documentation, what are our options to scale the cluster size to the minimum, when not in use, and be able to spin it back up, when required.  
Each cloud provider has its pricing options for provisioning Kubernetes clusters – for example, we might want to choose reserved instances or saving plans for production clusters that will be running 24/7, while for temporary Dev or Test environment, we might want to choose Spot instances and save cost.  

#### Additional References:
* [Cost optimization for Kubernetes on AWS](https://aws.amazon.com/blogs/containers/cost-optimization-for-kubernetes-on-aws/)  
* [5 steps to bringing Kubernetes costs in line](https://www.infoworld.com/article/3693050/5-steps-to-bringing-kubernetes-costs-in-line.html)  
* [4 Strategies for Kubernetes Cost Reduction](https://containerjournal.com/features/4-strategies-for-kubernetes-cost-reduction/)  

### Knowledge gap
Running Kubernetes clusters requires a lot of knowledge.  
From the design, provision, and maintenance, usually done by DevOps or experienced cloud engineers, to the deployment of new applications, usually done by development teams.  
It is crucial to invest in employee training, in all aspects of Kubernetes.  
Constant updates using vendor documentation, online courses, blog posts, meetups, and technical conferences will enable teams to gain the knowledge required to keep up with Kubernetes updates and changes.  

#### Additional References:
* [Kubernetes Blog](https://kubernetes.io/blog/)  
* [AWS Containers Blog](https://aws.amazon.com/blogs/containers/)  

### Third-party integration
Kubernetes solve part of the problems related to container orchestration.  
As an open-source solution, it can integrate with other open-source complimentary solutions (from monitoring, security and governance, cost management, and more).  
Every organization might wish to use a different set of tools to achieve each task relating to the ongoing maintenance of the Kubernetes cluster or for application deployment.  
Selecting the right tools can be challenging as well, due to various business or technological requirements.  
It is recommended to evaluate and select Kubernetes native tools to achieve the previously mentioned tasks or resolve the mentioned challenges.  

## Summary
In this blog post, I have reviewed the most common Day 2 Kubernetes challenges.  
I cannot stress enough the importance of employee training in deploying and maintaining Kubernetes clusters.  
It is highly recommended to evaluate and look for a centralized management platform for deploying, monitoring (using cloud-native tools), and securing the entire fleet of Kubernetes clusters in the organization.  
Another important recommendation is to invest in automation – from policy enforcement to application deployment and upgrade, as part of the CI/CD pipeline.  
I recommend you continue learning and expanding your knowledge in the ongoing changed world of Kubernetes.  

### About the Author
Eyal Estrin is a cloud and information security architect, the owner of the blog [Security & Cloud 24/7](https://security-24-7.com/) and the author of the book [Cloud Security Handbook](https://amzn.to/3xMI4Ak), with more than 20 years in the IT industry.  
Eyal is an [AWS Community Builder](https://aws.amazon.com/developer/community/community-builders/) since 2020.  
You can connect with him on [Twitter](https://twitter.com/eyalestrin) and [LinkedIn](https://www.linkedin.com/in/eyalestrin/).