首页 > 其他分享 >Kubernetes Antipatterns

Kubernetes Antipatterns

时间:2024-03-24 22:23:18浏览次数:39  
标签:container Antipatterns Kubernetes practice application production Best

In Kubernetes, identifying and avoiding anti-patterns is crucial for maintaining a robust container orchestration environment. These misleading practices may initially appear effective but can lead to complications. This reading explores ten prevalent Kubernetes anti-patterns and recommends alternative practices for a smoother and more sustainable deployment.

1. Avoid baking configuration in container images

Containers offer the advantage of using a consistent image throughout the production process. To achieve adaptability across different environments, building images without embedding configuration directly into containers is essential.

Issue: Problems arise when images contain environment-specific artifacts that deviate from the tested version, necessitating image rebuilds and risking inadequately tested versions in production. Identification of environment-dependent container images involves spotting features like hardcoded IP addresses, passwords, and environment-specific prefixes.

Best practice: Create generic images independent of specific runtime settings. Containers enable the consistent use of a single image throughout the software lifecycle, promoting simplicity and efficiency.

2. Separate application and infrastructure deployment

Infrastructure as Code (IaC) allows defining and deploying infrastructure like writing code. While deploying infrastructure through a pipeline is advantageous, separating infrastructure and application deployment is crucial.

Issue: Using a single pipeline for both infrastructure and application deployment leads to resource and time wastage, especially when changes in application code outpace infrastructure changes.

Best practice: Split infrastructure and application deployment into separate pipelines to optimize efficiency and resource utilization.

3. Eliminate specific order in deployment

Maintaining application stability despite delays in dependencies is crucial in container orchestration. Unlike traditional fixed startup orders, Kubernetes and containers initiate components simultaneously.

Issue: Challenges arise when poor network latency disrupts communication, potentially causing pod crashes or temporary service unavailability.

Best practice: Proactively anticipate failures, establish frameworks to minimize downtime, and adopt strategies for simultaneous component initiation to enhance application resilience.

4. Set memory and CPU limits for pods problem

The default Kubernetes setting without specified resource limits allows an application to potentially monopolize the entire cluster, causing disruptions.

Best practice: Establish resource limits for all applications, conduct a thorough examination of each application's behavior under various conditions, and strike the right balance to optimize cluster performance.

5. Avoid pulling the latest tag in production problem

The utilization of the "latest" tag in production settings often results in unforeseen pod crashes, triggered by sporadic image pulls lacking specificity. This absence of clear versioning makes troubleshooting challenging, particularly during downtime resolution where swift identification of issues is paramount.

Best practice: Use specific and meaningful image tags, incorporating possibly the date and time of the build. Furthermore, it is crucial to uphold the immutability of container images and store data externally in persistent storage. Avoiding post-deployment modifications to containers ensures safer and more repeatable deployment processes.

6. Segregate production and non-production workloads problem

Relying on a single cluster for all operational needs poses challenges. Security concerns arise from default permissions and complications with non-namespaced Kubernetes resources.

Best practice: Establish a second cluster exclusively for production purposes, avoiding complexities associated with multi-tenancy. Maintain at least two clusters—one for production and one for non-production.

7. Refrain from ad-hoc deployments with kubectl edit/patch problem

Configuration drift occurs when multiple environments deviate due to unplanned deployments or changes, leading to failed deployments.

Best practice: Conduct all deployments through Git commits for comprehensive history, precise knowledge of cluster contents, and easy recreation or rollback of environments.

8. Implement health checks with liveness and readiness probes problem

Neglecting health checks can lead to various issues. Overly complex health checks with unpredictable timings can cause internal denial-of-service attacks within the cluster.

Best practice: Configure health probes for each container, use liveness and readiness probes, and prioritize robust health checks for reliable application responsiveness.

9. Prioritize secret handling and use vault problem

Embedding secrets directly into containers is poor practice. Using multiple secret handling methods or complex injection mechanisms can complicate local development and testing.

Best practice: Use a consistent secret handling strategy, consider HashiCorp Vault, handle secrets uniformly across environments, and pass them to containers during runtime for enhanced resilience and security.

10. Use controllers and avoid running multiple processes per container problem

Directly using pods in production poses limitations. Pods lack durability, automatic rescheduling, and data retention guarantees. Running multiple processes in a single container without controllers can lead to issues.

Best practice: Utilize Deployment with a replication factor, define one process per container, use multiple containers per pod if necessary, and leverage workload resources like Deployment, Job, or StatefulSet for reliability and scalability.

Conclusion

Understanding and avoiding these Kubernetes anti-patterns contribute to a more resilient and efficient container orchestration environment. Embracing best practices ensures smoother deployments, reduces technical debt, and enhances the overall stability of Kubernetes-based applications.

 

标签:container,Antipatterns,Kubernetes,practice,application,production,Best
From: https://www.cnblogs.com/jbite9057/p/18093212

相关文章

  • Kubernetes一文上手【手把手系列】
    目录Kubernetes前言部署方式的演变K8S概述K8S架构Master节点1.APIServer2.Etcd3.ControllerManager4.SchedulerNode节点1.kubelet2.kube-proxy3.容器运行时组件与插件1.KubernetesDNS2.Dashboard3.Heapster4.IngressControllerK8S核心概念PodSerivce......
  • Kubernetes客户端认证(三)—— Kubernetes使用CertificateSigningRequest方式签发客户端
    1、概述在《Kubernetes客户端认证(一)——基于CA证书的双向认证方式 》和《Kubernetes客户端认证(二)——基于ServiceAccount的JWTToken认证》两篇博文中详细介绍了Kubernetes客户端认证方式,包括以证书方式访问的普通用户或进程(运维人员及kubectl、kubelet等进程);以Service......
  • Kubernetes之Service
    一、Service的概念与定义1.Service的概念Service是Kubernetes实现微服务架构的核心概念,主要用于提供网络服务。通过Service的定义,可以对客户端应用屏蔽后端Pod实例数量及PodIP地址的变化,通过负载均衡策略实现请求到后端Pod实例的转发,为客户端应用提供一......
  • Kubernetes之Pod调度策略
    一、NodeSelector:定向调度1.基本原理在Kubernetes上部署应用时,有时候可能需要限制Pod的调度范围,将Pod调度到指定的一些Node上。此时,可以为需要调度的这些Node打上标签,同时设置Pod的nodeSelector属性,使二者相匹配来达到定向调度的目的。2.简单实践(1)为目标......
  • Kubernetes之Pod工作负载
    Pod工作负载,亦称Pod控制器。在Kubernetes平台上,我们很少会直接创建一个Pod,因为直接管理单个Pod的工作量将会非常繁琐。我们可以使用KubernetesAPI创建工作负载对象,这些对象所表达的是比Pod更高级别的抽象概念,Kubernetes 控制平面根据我们定义的工作负载对象规......
  • [Container] Introduction to Kubernetes
    DefineKubernetesAlsoknowasK8S,isanopen-sourcesystemforautomatingdeployment,scaling,andmanagementofcontainerizedapplications.Anopensourcecontainerizationorchestrationpaltform.Easolyportableacrosscloudsandon-premisesIncludes......
  • Win7下做一个Kubernetes的NetCore项目Demo
    建立K8s集群Demo,将一个建立好的AspNetCore项目加入到集群中。一准备工作IDEVS2017Win7下需要dockertools(打包Dockerimage)一个VM,笔者用的是VMwareWorkstationPro15(破解版)注册一个https://hub.docker.com/账户安装一个WinSCP用来windows和linux传送文件,......
  • K8S单机部署-11.安装Kubernetes Metrics Server监控
    目录现象安装Metric-Server版本关系下载部署文件修改镜像地址部署验证效果问题一原因解决办法现象当需要查看资源的占用的时候执行以下命令,提示缺少组件:[root@masterk8s-metric-server]#kubectltoppoderror:MetricsAPInotavailable安装Metric-Server......
  • 如何在Kubernetes集群中集成Cromwell和Volcano(概述)
    将Cromwell和Volcano在Kubernetes集群中集成,使用Volcano作为Cromwell调度器,涉及到在Kubernetes集群上安装和配置这两个系统以及确保它们能够无缝协作。以下是一个基于理解和实际操作经验的概括步骤,旨在指导如何进行这一集成:步骤1:安装Kubernetes集群确保你已经......
  • Kubernetes之Pod基本原理与实践
    一、Pod的定义与基本用法1.Pod是什么Pod是可以在Kubernetes中创建和管理的、最小的可部署的计算单元。Pod不是进程,而是容器运行的环境。Pod所建模的是特定于应用的“逻辑主机”,其中包含一个或多个应用容器。当Pod包含多个应用容器时,这些容器的应用之间应该是......