💻
Software Development
Technical Knowledges
Technical Knowledges
  • Everything anyone should know
    • Fundamental
      • Life cycle of Dependency Injection
        • When to use?
          • Transient
          • Scoped
          • Singleton
      • OOP
        • Inheritance
          • More with override in C#
            • Why need to use "virtual" keyword when we can use "new" keyword
          • How to achieve multiple inheritance in C#
          • Note
        • Polymophism
        • Encapsulation
        • Abtraction
          • Not use "override" keyword in abstract method
          • Notes
      • Data representing
        • JSON
        • XML
        • Comparation
      • Middleware
      • Status Code
      • API Styles
        • SOAP
        • REST
          • Question
        • GraphQL
        • gRPC
        • WebSocket
        • Webhook
        • Comparation
          • SOAP vs REST
          • REST vs GraphQL
          • gRPC vs REST
          • HTTP vs WebSocket
      • SDK
    • Advanced
      • Memoize
      • N+1 issues
      • Concurrency
        • Thread
          • Race Condition
          • Thread Safety
          • Critical Sections
        • Deadlock
        • Semaphore
    • Comparison
      • Architecture
        • SOA vs Microservices
        • Strong Consistency vs Eventual Consistency
      • Data structures
        • Instance vs Object
        • Field vs Property
        • Properties vs Method
        • Class vs Struct
        • const vs readoly vs static
        • Value types and Reference types
        • i++ vs ++i
        • Prototypal Inheritance vs Class Inheritance
        • Abstraction vs Interface
        • Run-time vs Compile-time
        • Overloading vs Overriding
      • Front-end
        • SSR vs SPA
        • Axios vs Fetch
      • Databases
        • Different between Function() and Store Procedure()
      • Security
        • Encoding vs Encryption vs Tokenization
      • Message Broker
        • RabbitMQ vs Kafka
      • Devops
        • Kubernetes vs Docker Swarm
        • Docker Repository vs Docker Registry
      • Cloud
      • Computer Science
        • Recursion and Iteration
      • Technology
        • .NET Core vs .NET Framework
        • Cache vs Local Storage vs Session Storage vs Cookies
      • SDLC
        • TDD vs BDD
  • Design Pattern
    • Overview
    • Creational Design Patterns
      • Abstract Factory
        • Code Example
          • C#
          • Java
          • Python
      • Builder
        • Code Example
          • C#
          • Java
          • Python
      • Factory Method
        • Code Example
          • C#
          • Java
          • Python
      • Prototype
        • Code example
          • C#
          • Java
          • Python
      • Singleton
        • Code example
          • C#
            • Naïve Singleton
            • Thread-safe Singleton
          • Java
            • Naïve Singleton (single-threaded)
            • Naïve Singleton (multithreaded)
            • Thread-safe Singleton with lazy loading
          • Python
            • Naïve Singleton
            • Thread-safe Singleton
    • Structural Design Patterns
      • Adapter
        • Code example
          • C#
          • Java
          • Python
            • Conceptual Example (via inheritance)
            • Conceptual Example (via object composition)
      • Bridge
        • Code example
          • C#
          • Java
          • Python
      • Composite
        • Code example
          • C#
          • Java
          • Python
      • Decorator
        • Code example
          • C#
          • Java
          • Python
      • Facade
        • Code example
          • C#
          • Java
          • Python
      • Flyweight
        • Code example
          • C#
          • Java
          • Python
      • Proxy
        • Code example
          • C#
          • Java
          • Python
    • Behavior Design Patterns
      • Chain of Responsibility
        • Code example
          • C#
          • Java
          • Python
      • Command
        • C#
        • Java
        • Python
      • Interpreter
        • Code example
          • C#
      • Iterator
        • Code example
          • C#
          • Java
          • Python
      • Mediator
        • Code example
          • C#
          • Java
          • Python
      • Memento
        • Code example
          • C#
          • Java
          • Python
      • Observer
        • Code example
          • C#
          • Java
          • Python
      • State
        • Code example
          • C#
          • Java
          • Python
      • Strategy
        • Code example
          • C#
          • Java
          • Python
        • Different with using abstract class
      • Template Method
        • Code example
          • C#
          • Java
          • Python
      • Visitor
        • Code example
          • C#
          • Java
          • Python
    • Use cases
      • Real-life example
    • More
      • Circuit Breaker Pattern
      • Repository Pattern
      • Unit Of Work Pattern
    • Some design patterns contradictory
  • Architect
    • Clean Architecture
    • Layered (n-tier) Architecture
    • Microservices Architecture
    • Monolithic Architecture
    • Service-Oriented Architecture (SOA)
    • Domain-Driven Design (DDD)
    • Blackboard Architecture
    • Object-Oriented Architecture
  • Microservices Design Pattern
    • Saga Pattern
      • Example
    • Strangler Fig Pattern
    • API Gateway Pattern
    • Backends For Frontends (BFF) Pattern
    • Service Discovery Pattern
    • Circuit Breaker Pattern
    • Bulk Head Pattern
    • Retry Pattern
    • Sidecar Pattern
    • Event Driven Architecture Pattern
    • CQRS (Command and Query Responsibility Segregation)
      • Event Sourcing
      • Code example
        • Basic
        • CQRS + MediatR + EDA + RabbitMQ
      • The Good, the Bad, and the Ugly
    • Configuration Externalization Pattern
  • Design and development principles
    • SOLID aka Design Principles
    • Cohesion Principles
    • Coupling principle
    • Some fundamental principles
      • Separation of Concerns
      • Persistence Ignorance
      • DRY
      • KISS
  • Authentication and Authorization Standards
    • SAML
    • OAuth
    • OIDC
    • SCIM
    • SSO
    • Tools
      • Keycloak
    • More
      • JWT
      • Access Token & Refresh Token
  • .NET TECHNOLOGY
    • .NET MVC
      • HTML Helpers
        • Extension method for HTML Helpers
      • Filters
        • Order of Filters
    • Fundamental
      • Startup file
      • Query Data
        • Linq
          • Filtering
          • Sorting
          • Projecting
          • Quantifying
          • Flattening
          • Grouping
          • Joining
          • Aggregating
          • Deferred execution vs Immediate execution
        • OData
          • Filter Expression
      • ORM
        • Entity Framework
          • Eager Loading vs Lazy Loading vs Explicit Loading
          • How to improve our entity framework core query performance
        • Dapper
        • Why Dapper faster than Entity Framework
      • Identity Server
      • Fluent Validation
      • Minimal API
      • Generic
      • IoC
        • Castle Windsor
        • Autofac
        • Ninject
      • CLR
      • Refit
      • Task Schedule
        • Hangfire
        • Quartz
      • Some notice
    • Advanced
      • Multi Thread
        • Thread pool
        • Parallel
        • Comparation
        • Code comparation
      • Caching
        • IMemoryCache
      • MediatR
      • SignalR
      • API Gateway
        • Ocelot
      • gRPC
      • Multitenancy
      • Special C# technique
        • Generic
        • Extension Method
        • Delegate
        • Lambda Expression
        • Yield
      • Jetbrain tools
        • dotTrace
        • dotMemory
        • dotPeek
      • ABP Framework
        • Multi Layered
          • Domain Layer
            • Entities
            • Repository
            • Domain Services
          • Application Layer
            • Application Services
            • Data Transfer Objects
          • Data Access
            • Entity Framework Core Integration
            • MongoDB Integration
        • Microservice Architecture
        • DDD
          • Domain Layer
            • Entities & Aggregate Roots
            • Value Objects
            • Repositories
            • Domain Services
            • Specifications
          • Application Layer
            • Application Services
            • Data Transfer Objects
            • Unit of Work
    • Tutorial Coding
      • Custom and Using Middleware in .NET CORE
      • Connect Elastic Search and MongoDB
      • Implementing the Unit of Work Pattern in Clean Architecture with .NET Core
    • ServiceStack
    • POCO
  • System Design
    • Blueprint
    • Fundamental
      • Scale from zero to millions of users
        • Single server setup
        • Database
        • Load balancer
        • Database replication
        • Cache
        • Content delivery network (CDN)
        • Stateless web tier
        • Data centers
        • Message queue
        • Logging, metrics, automation
        • Database scaling
        • Millions of users and beyond
      • A framework for system design interviews
        • Step 1 - Understand the problem and establish design scope
        • Step 2 - Propose high-level design and get buy-in
        • Step 3 - Design deep dive
        • Step 4 - Wrap up
        • Summarize
      • Back-of-the-envelope estimation
      • Design a rate limiter
        • Step 1 - Understand the problem and establish design scope
        • Step 2 - Propose high-level design and get buy-in
          • Algorithms for rate limiting
            • Token bucket algorithm
            • Leaking bucket algorithm
            • Fixed window counter algorithm
            • Sliding window log algorithm
            • Sliding window counter algorithm
          • High-level architecture
        • Step 3 - Design deep dive
          • Rate limiting rules
          • Exceeding the rate limit
          • Detailed design
          • Rate limiter in a distributed environment
          • Performance optimization
          • Monitoring
        • Step 4 - Wrap up
      • Design consistent hashing
        • Consitent hashing
        • Two issues in the basic approach
        • Wrap up
      • Design key-value store
        • Understand the problem and establish the design scope
        • CAP theorem
        • System components
          • Data partition
          • Data replication
          • Consistency
          • Inconsistency resolution
          • Handling failures
          • System architecture diagram
          • Write path
          • Read path
      • Design a unique id generator in distributed systems
        • Step 1 - Understand the problem and establish design scope
        • Step 2 - Propose high-level design and get buy-in
          • Multi-master replication
          • UUID
          • Ticket Server
          • Twitter snowflake approach
        • Step 3 - Design deep dive
        • Step 4 - Wrap up
      • Design a url shortener
        • Step 1 - Understand the problem and establish design scope
        • Step 2 - Propose high-level design and get buy-in
        • Step 3 - Design deep dive
          • Data model
          • Hash function
          • URL shortening deep dive
          • URL redirecting deep dive
        • Step 4 - Wrap up
      • Design a web crawler
        • Step 1 - Understand the problem and establish design scope
        • Step 2 - Propose high-level design and get buy-in
        • Step 3 - Design deep dive
          • DFS vs BFS
          • URL frontier
          • HTML Downloader
          • Robustness
          • Extensibility
          • Detect and avoid problematic content
        • Step 4 - Wrap up
    • Use cases
      • Design Youtube
      • Design Social Media App
      • Design Typehead Suggestion
      • Design Taxi Booking System
      • Design Messaging App
  • DBMS
    • Fundamental
      • ACID
      • Order Of Execution of the SQL query
      • Transaction – Concurrency Control Techniques
        • Isolation level
      • Index
        • Clustered Index vs Non-clustered index
        • Index vs Unique index
      • Built-in functions
        • String Functions
          • ASCII
          • CHAR
          • CHARINDEX
          • CONCAT
          • CONCAT_WS
          • DATALENGTH
          • DIFFERENCE
          • FORMAT
          • LEFT
          • LEN
          • LOWER
          • LTRIM
          • NCHAR
          • PATINDEX
          • QUOTENAME
          • REPLACE
          • REPLICATE
          • REVERSE
          • RIGHT
          • RTRIM
          • SOUNDEX
          • SPACE
          • STR
          • STUFF
          • SUBSTRING
          • TRANSLATE
          • TRIM
          • UNICODE
          • UPPER
        • Numeric Functions
          • ABS
          • ACOS
          • ASIN
          • ATAN
          • ATN2
          • AVG
          • CEILING
          • COUNT
          • COS
          • DEGREES
          • EXP
          • FLOOR
          • LOG
          • LOG10
          • MAX
          • MIN
          • PI
          • POWER
          • RADIANS
          • ROUND
          • SIGN
          • SIN
          • SQRT
          • SQUARE
          • SUM
          • TAN
        • Date Functions
          • CURRENT_TIMESTAMP
          • DATEADD
          • DATEDIFF
          • DATEFROMPARTS
          • DATENAME
          • DATEPART
          • DAY
          • GETDATE
          • GETUTCDATE
          • ISDATE
          • MONTH
          • SYSDATETIME
          • YEAR
        • Advance Functions
          • CASE
          • CAST
          • COALESCE
          • CONVERT
          • CURRENT_USER
          • LEAD
          • LAG
          • IIF
          • ISNULL
          • ISNUMERIC
          • NULLIF
          • SESSION_USER
          • SESSIONPROPERTY
          • SYSTEM_USER
          • USER_NAME
      • SQL Best Practice
      • Execution Plan
      • Optimize query execution
    • Advanced
      • CTE
      • Window function
      • Performance Tuning
        • Query tuning
        • Interview ques
      • DB Sharding
      • Concurrency Control
        • Optimistic lock
        • Pessimistic lock
      • Compare DELETE VS TRUNCATE
    • Comparation
      • Oracle vs SQL Server vs Postgre vs Mysql
  • Javascript
    • ES6 Techniques
      • Hoisting
      • Destructing
      • Spread Operator
      • Rest Operator
    • Basic
      • Const vs Let vs Var
      • Debounce & Throttle
      • Callback()
    • 5 ways to define a function
  • Clean code
    • Page 2
  • Search Engine
    • Elastic Search
      • Interview question
      • Code Example
    • Solr
    • IBM Watson Discovery
    • Google Cloud Search
    • Coveo Relevance Cloud
  • Cloud Service
    • Overview
    • Azure
      • Certificate
        • AZ-900
          • Describe cloud concepts
            • What is Cloud Computing?
            • Benefits of using cloud services
              • High Availability and Scalability
              • High Elasticity
              • High Reliability and Predictability
              • High Security and Governance
              • High manageability
            • IaaS vs PaaS vs SaaS
            • Cloud Deployment Models
            • CAPEX vs OPEX
          • Describe Azure architecture and services
            • Describe the core architectural components of Azure
              • Learn sandbox
              • Azure physical infrastructure
              • Azure management infrastructure
              • Create an Azure resource
            • Describe Azure compute and networking services
              • Azure Virtual Machines
              • Create an Azure Virtual Machine
              • Azure Virtual Desktop
              • Azure Containers
              • Azure Function
              • Describe application hosting options
              • Configure network access
              • Describe Azure Virtual Networking
              • Azure Virtual Private Networks
              • Azure ExpressRoute
              • Azure DNS
            • Describe Azure storage services
              • Azure storage accounts
              • Azure storage redundancy
              • Azure storage services
              • Create a storage blob
              • Identify Azure data migration options
              • Identify Azure file movement options
            • Describe Azure identity, access, and security
              • Azure directory services
              • Azure authentication methods
              • Azure external identities
              • Azure conditional access
              • Azure role-based access control
              • Zero trust model
              • Defense-in-depth
              • Microsoft Defender for Cloud
          • Describe Azure management and governance
            • Describe cost management in Azure
              • Factors that can affect costs in Azure
              • Compare the Pricing and Total Cost of Ownership calculators
              • Estimate workload costs by using the Pricing calculator
              • Compare workload costs using the TCO calculator
              • Azure Cost Management tool
            • Describe features and tools in Azure for governance and compliance
              • Azure Blueprints
              • Azure Policy
              • Purpose of resource locks
              • Configure a resource lock
              • Service Trust portal
            • Describe features and tools for managing and deploying Azure resources
              • Tools for interacting with Azure
              • Azure Arc
              • Azure Resource Manager and Azure ARM templates
            • Describe monitoring tools in Azure
              • Azure Advisor
              • Azure Service Health
              • Azure Monitor
        • SC-900
          • Describe the concepts of security, compliance, and identity
            • Describe security and compliance concepts
              • Shared responsibility model
              • Defense in depth
              • Zero Trust model
              • Encryption and hashing
              • Compliance concepts
            • Describe identity concepts
              • Authentication and authorization
              • Identity as the primary security perimeter
              • Role of the identity provider
              • Directory services and Active Directory
              • Federation
          • Describe the capabilities of Microsoft Azure Active Directory, part of Microsoft Entra
            • Describe the services and identity types of Azure AD
              • Azure Active Directory
              • Available Azure AD editions
              • Azure AD identity types
              • Types of external identities
              • Concept of hybrid identity
            • Describe the authentication capabilities of Azure AD
              • Authentication methods available in Azure AD
              • Multi-factor authentication (MFA) in Azure AD
              • Self-service password reset (SSPR) in Azure AD
              • Password protection and management capabilities of Azure AD
            • Describe the access management capabilities of Azure AD
              • Conditional Access in Azure AD
              • Benefits of Azure AD roles and role-based access control
            • Describe the identity protection and governance capabilities of Azure AD
              • Identity governance in Azure AD
              • Entitlement management and access reviews
              • Privileged identity Management
              • Azure Identity Protection
          • Describe the capabilities of Microsoft security solutions
            • Describe basic security capabilities in Azure
              • Azure DDoS protection
              • Azure Firewall
              • Web Application Firewall
              • Network segmentation in Azure
              • Azure Network Security groups
              • Azure Bastion and JIT Access
              • Describe ways Azure encrypts data
            • Describe security management capabilities of Azure
              • Cloud security posture management
              • Microsoft Defender for Cloud
              • Enhanced security of Microsoft Defender for Cloud
              • Microsoft cloud security benchmark and security baselines for Azure
            • Describe security capabilities of Microsoft Sentinel
              • SIEM and SOAR
              • How Microsoft Sentinel provides integrated threat management
              • Understand Sentinel costs
            • Describe threat protection with Microsoft 365 Defender
              • Microsoft 365 Defender services
              • Microsoft Defender for Office 365
              • Microsoft Defender for Endpoint
              • Microsoft Defender for Cloud Apps
              • Microsoft Defender for Identity
              • Microsoft 365 Defender portal
          • Describe the capabilities of Microsoft compliance solutions
            • Describe the Service Trust Portal and privacy at Microsoft
              • Service Trust Portal
              • Microsoft's privacy principles
              • Microsoft Priva
            • Describe the compliance management capabilities in Microsoft Purview
              • Microsoft Purview compliance portal
              • Compliance Manager
              • Describe use and benefits of compliance score
            • Describe information protection and data lifecycle management in Microsoft Purview
              • Know your data, protect your data, and govern your data
              • Data classification capabilities of the compliance portal
              • Sensitivity labels and policies
              • Data loss prevention
              • Retention policies and Retention labels
              • Records management
            • Describe insider risk capabilities in Microsoft Purview
              • Risk management
              • Communication compliance
              • Information barriers
            • Describe the eDiscovery and audit capabilities of Microsoft Purview
              • eDiscovery solutions in Microsoft Purview
              • Audit solutions in Microsoft Purview
            • Describe resource governance capabilities in Azure
              • Azure Policy
              • Azure Blueprints
              • Capabilities in the Microsoft Purview governance portal
        • DP-900
          • Core Concept
            • Explore core data concepts
              • Data formats
              • File storage
              • Databases
              • Transactional data processing
              • Analytical data processing
            • Explore data roles and services
              • Job roles in the world of data
              • Identify data services
          • Relational Data in Azure
            • Explore fundamental relational data concepts
              • Relational data
              • Normalization
              • SQL
              • Database objects
            • Explore relational database services in Azure
              • Azure SQL services and capabilities
              • Azure services for open-source databases
              • Exercise: Explore Azure relational database services
          • Non-relational data in Azure
            • Explore Azure Storage for non-relational data
              • Azure blob storage
              • Azure DataLake Storage Gen2
              • Azure Files
              • Azure Tables
              • Exercise: Explore Azure Storage
            • Explore fundamentals of Azure Cosmos DB
              • Azure Cosmos DB
              • Identify Azure Cosmos DB APIs
              • Exercise: Explore Azure Cosmos DB
          • Data analytics in Azure
            • Explore fundamentals of large-scale data warehousing
              • Data warehousing architecture
              • Data ingestion pipelines
              • Analytical data stores
              • Exercise: Explore data analytics in Azure with Azure Synapse Analytics
            • Explore fundamentals of real-time analytics
              • Understand batch and stream processing
              • Explore common elements of stream processing architecture
              • Azure Stream Analytics
              • Exercise: Explore Azure Stream Analytics Completed
              • Apache Spark on Microsoft Azure
              • Exercise: Explore Spark Streaming in Azure Synapse Analytics Completed
            • Explore fundamentals of data visualization
              • Power BI tools and workflow
              • Core concepts of data modeling
              • Considerations for data visualization
              • Exercise – Explore fundamentals of data visualization with Power BI Completed
        • AI-900
      • Azure Subscription
      • Azure App Service
      • Azure Dictionary B2C
      • Azure Front Door
      • Azure Traffic Manager
      • Azure Load Balancer
      • Azure KeyVault
      • API Management
      • Azure Logic Apps
      • Azure Metric and Logs
      • Azure Workbooks
      • Azure Messaging Services
      • Azure Service Fabric
      • Comparison
        • Durable Function vs Logic App
        • Storage queues vs Service Bus queues
        • Event Grid vs Service Bus
    • AWS
      • Certificate
        • CLF-C02
          • Cloud Concepts
            • Cloud Computing
            • The Deployment Models of the Cloud
            • The Five Characteristics of Cloud Computing
            • Six Advantages of Cloud Computing
            • Problems solved by the Cloud
            • Types of Cloud Computing
            • Pricing of the Cloud
            • AWS Global Infrastructure
              • AWS Regions
              • AWS Availability Zones
              • AWS Points of Presence (Edge Locations)
            • Tour of the AWS Console
            • Shared Responsibility Model diagram
          • Security & Compliance
            • AWS Shared Responsibility Model
            • DDOS
            • Network Firewall
            • Penetration Testing on AWS Cloud
            • Encryption
            • AWS Certificate Manager (ACM)
            • AWS Secrets Manager
            • AWS Artifact (not really a service)
            • Amazon GuardDuty
            • Amazon Inspector
            • AWS Config
            • AWS Macie
            • AWS Security Hub
            • Amazon Detective
            • AWS Abuse
            • Root user privileges
            • IAM Access Analyzer
            • Summary
            • Advanced Identity
              • STS
              • Cognito
              • Directory Services
              • IAM Identity Center
              • Summary
          • Cloud Technology & Services
            • IAM
              • IAM: Users & Groups
              • IAM: Permissions
              • IAM Policies inheritance
              • IAM Policies Structure
              • IAM – Password Policy
              • Multi-Factor Authentication - MFA
              • How can users access AWS?
                • AWS CLI
                • AWS SDK
              • IAM Roles for Services
              • IAM Security Tools
              • IAM Guidelines & Best Practices
              • Shared Responsibility Model for IAM
              • Summary
            • EC2
              • Overview
              • EC2 Instance Types
                • Overview
                • General Purpose
                • Compute Optimized
                • Memory Optimized
                • Storage Optimized
                • Example
              • Security Groups
              • SSH in EC2
              • EC2 Instance Purchasing Options
                • On-Demand Instances
                • Reserved Instances
                • Savings Plans
                • Spot Instances
                • Dedicated Hosts
                • Dedicated Instances
                • Capacity Reservations
                • Summary
              • EC2 Instance Storage
                • EBS
                • EBS Snapshot
                • AMI
                • EC2 Image Builder
                • EC2 Instance Store
                • EFS
                • Shared Responsibility Model for EC2 Storage
                • Amazon FSx
                • Summary
            • ELB & ASG
              • High Availability, Scalability, Elasticity
              • ELB
              • ASG
              • Summary
            • Amazon S3
              • Overview
              • Security
              • Techniques
              • Shared Responsibility Model for S3
              • AWS Snow Family
              • Summary
            • Database & Analytics
              • Overview
              • RDS & Aurora
              • Amazon ElastiCache
              • DynamoDB
              • Redshift
              • EMR
              • Amazon Athena
              • Amazon QuickSight
              • DocumentDB
              • Amazon Neptune
              • Amazon QLDB
              • Amazon Managed Blockchain
              • AWS Glue
              • DMS – Database Migration Service
              • Summary
            • Other Compute Service
              • Docker
              • ECS
              • Fargate
              • ECR
              • AWS Lamda
              • Amazon API Gateway
              • AWS Batch
              • Amazon Lightsail
              • Summary
                • Other Compute - Summary
                • Lambda Summary
            • Deploying and Managing Infrastructure
              • CloudFormation
              • CDK
              • Elastic Beanstalk
              • AWS CodeDeploy
              • AWS CodeCommit
              • AWS CodePipeline
              • AWS CodeArtifact
              • AWS CodeStar
              • AWS Cloud9
              • SSM
              • AWS OpsWorks
              • Summary
            • Global Infrastructure
              • Overview
              • Route 53
              • CloudFront
              • AWS Global Accelerator
              • AWS Outposts
              • AWS WaveLength
              • AWS Local Zones
              • Global Applications Architecture
              • Summary
            • Cloud Integration
              • Overview
              • SQS
              • Kinesis
              • SNS
              • MQ
              • Summary
            • Cloud Monitoring
              • CloudWatch
              • EventBridge
              • CloudTrail
              • X-Ray
              • CodeGuru
              • Health Dashboard
              • Summary
            • VPC
              • Overview
              • IP Addresses in AWS
              • VPC Diagram
              • Core networking
              • VPC Flow Logs
              • VPC Peering
              • VPC Endpoints
              • AWS PrivateLink (VPC Endpoint Services)
              • Site to Site VPN & Direct Connect
              • AWS Client VPN
              • Transit Gateway
              • Summary
            • Machine Learning
              • Rekognition
              • Transcribe
              • Polly
              • Translate
              • Lex & Connect
              • Comprehend
              • SageMaker
              • Forecast
              • Kendra
              • Personalize
              • Textract
              • Summary
            • Other Services
              • WorkSpaces
              • AppStream 2.0
              • IoT Core
              • Elastic Transcoder
              • AppSync
              • Amplify
              • Device Farm
              • Backup
              • Disaster Recovery Strategies
              • AWS Elastic Disaster Recovery (DRS)
              • DataSync
              • Application Discovery Service
              • Application Migration Service (MGN)
              • Migration Evaluator
              • Migration Hub
              • FIS
              • Step Functions
              • Ground Station
              • Pinpoint
          • Account Management, Billing & Support
            • Organizations
            • SCP
            • Control Tower
            • RAM
            • Service Catalog
            • Savings Plan
            • AWS Compute Optimizer
            • Billing and Costing Tools
            • Pricing Calculator
            • Tracking costs in cloud
              • Cost Explorer
            • Monitoring costs in the could
            • AWS Cost Anomaly Detection
            • AWS Service Quotas
            • Trusted Advisor
            • Support Plans
            • Summary
              • Account Best Practices
              • Billing and CostingTools
          • AWS Architecting & Ecosystem
            • General Guiding Principles
            • Well Architected Framework
              • Operational Excellence
              • Security
              • Reliability
              • Performance Efficiency
              • Cost Optimization
              • Sustainability
            • AWS CAF
            • AWS Right Sizing
            • AWS Ecosystem
      • Comparison
        • Region, Availability Zone and Edge Location in AWS
        • EBS vs EFS
    • GCP
    • OCI
    • Object Storage Server
      • MinIO
    • Comparison
      • Azure Active Directory B2C vs AWS Cognito
  • Front End
    • Basic
      • HTML
        • <ul> vs <ol>
        • <table>
      • CSS
        • Padding
        • Box Model
        • Outline
        • Text
        • Display
        • Position
        • z-index
        • Overflow
        • Float
        • Inline vs Inline-block
        • CSS Combinators
        • CSS [attribute] Selector
        • Website Layout
        • Unit
        • CSS The !important Rule
        • Flexbox
        • Comparation
          • div.classname vs div .classname
          • .classname vs .clasname #id vs .classname#id
      • JQuery
        • Syntax
        • Document
      • AJAX
    • Modern Framework
      • React
        • HOC
        • State Management
          • Redux
            • Selector
            • Middleware
              • Saga
              • Thunk
          • MobX
        • Hooks
        • Life Cycle
          • React Lifecycle Methods
          • React Lifecycle Hooks
          • Comparation
        • Signals
      • Angular
        • Directives
          • Component Directives
          • Attribute Directives
            • Built-in
            • Building an Attribute Directive
          • Structural Directives
            • Built-in
            • Custom
        • Binding
        • Components
        • Routing
      • Vue
    • Compile & Module
      • Webpack
      • Babel
    • TypeScript
      • Cheat sheet
    • Blazor
      • WebAssembly
    • UI Library
      • Formik
      • Material UI
      • Tailwind CSS
    • Security
      • Top 7 Common Frontend Security Attacks
    • Some notices
  • Microservices
    • Service Mesh
    • Service Registry
    • Service Discovery
    • Composition
    • Orchestration
    • Transformation
    • Dapr
  • Network
    • Protocols
      • Overview
      • HTTP
      • MQTT
      • AMQP
      • FTP
      • TCP
      • UDP
      • ICMP
    • OSI Model
  • Cache
    • Redis
      • What data should and should not be cached
      • Use cache in
      • Demo in .NET
    • Hazelcast
    • Memcached
  • Message Broker
    • RabbitMQ
      • Demo in .NET
      • Interview Ques
      • Use case
    • Kafka
      • Top 5 Kafka Use Case
    • ActiveMQ
    • Masstransit
  • Bash Script
    • Linux file system
    • Cheat sheet
    • 18 Most-used Linux Commands
    • Interview Question
  • Devops
    • Overview
      • What is ?
      • IaC
      • SAFe
      • Progressive Delivery
        • Blue Green Deployments
        • Canary Deployments
        • A/B Test
      • Platform Engineering
    • Azure Pipeline
    • Docker
      • What is ?
      • Docker Engine
        • Image
        • Docker file
          • Some commands
        • Container
        • Network
        • Volume
          • Additional infomation
      • Docker CLI
      • Docker Compose
        • Additional
      • Docker Security
        • Best Practice
        • Additional Information
      • Docker Swarm
      • Storing
        • Docker Registry
        • Docker Hub
      • Summarize
    • Kubernetes
      • What is ?
        • Additional
      • Kubernetes Pod
      • Replication Controllers
      • ReplicaSets and DaemonSets
        • Additional
      • Kubernetes Services
      • Deployment
        • Additional
      • Volume
      • PersistentVolumes
        • Additional
      • Configuration
        • Additional
      • StatefulSets
        • Additional
      • Downward API
      • Kubernetes internals architecture
      • Pod internal
      • ServiceAccount and Role Based Access Control
      • Network
        • Additional
      • Managing and calculating resources used for Pods
      • Automatic scaling Pods and clusters
      • Advanced scheduling
        • Taints and tolerations
        • Node affinity and Pod affinity
        • Additional
      • Adding custom resource to Kubernetes
    • Openshift
    • IaC
      • Terraform
        • Definition
        • Why chose Terraform?
        • IAC with Terraform
          • Terraform Workflow
            • Terraform Init
            • Terraform Plan
            • Terraform Apply
            • Terraform Destroy
          • Terraform Syntax
        • Terraform Architecture
          • Variable in terraform
          • Variable Type Contraint
          • Terraform Output
          • Terraform Provisioners
        • Terraform State
          • The concept
          • Local and Remote State Storage
          • Persisting Terraform State in AWS S3
          • Hand on
        • Terraform Modules
          • Accessing and Using Terraform Modules
          • Interating with Terraform Module Inputs and Outputs
          • Hand on
        • Built-in Functions and Dynamic Blocks
          • Built-in Function
          • Terraform Type Constraints (Collection & Structural)
          • Terraform Dynamic Block
          • Hand on
        • Terraform CLI
          • Terraform CLI: fmt, taint & import
          • Hand on
            • Practicing Terraform CLI commands(fmt, taint, import)
            • Using Terraform CLI Commands (workspace and state) to Manipulate a Terraform deployment
      • Ansible
    • Jenkin
    • GitOps
      • What is ?
      • Argo CD
    • Monitoring
      • Prometheus and Grafana
      • New Relic
  • Web Server
    • Apache
    • Nginx
    • IIS
  • Security
    • How to prevent crawl data
    • SQL Injection
    • OWASP
      • Web Application Security Risks
        • Broken Access Control
        • Cryptographic Failures
        • Injection
        • Insecure Design
        • Security Misconfiguration
        • Vulnerable and Outdated Components
        • Identification and Authentication Failures
        • Software and Data Integrity Failures
        • Security Logging and Monitoring Failures
        • Server-Side Request Forgery
      • API Security Risks
        • Broken Object Level Authorization
        • Broken Authentication
        • Broken Object Property Level Authorization
        • Unrestricted Resource Consumption
        • Broken Function Level Authorization
        • Unrestricted Access to Sensitive Business Flows
        • Server Side Request Forgery
        • Security Misconfiguration
        • Improper Inventory Management
        • Unsafe Consumption of APIs
    • Security headers
      • HTTP Strict Transport Security (HSTS)
      • Content Security Policy (CSP)
      • Cross Site Scripting Protection (X-XSS-Protection)
      • X-Frame-Options
      • X-Content-Type-Options
      • X-Permitted-Cross-Domain-Policies
      • Public Key Pinning (PKP)
        • What is HTTP Public Key Pinning and Why It’s Not Good to Practice
      • Expect-CT
        • The end of Expect-CT
      • Referer-Policy
      • Pragma
      • Cache-Control
        • Difference between Pragma and Cache-Control headers
      • Same-origin policy
      • Cross-origin resource sharing (CORS)
  • Data Change Capture (CDC)
    • Debezium
  • Software Development Life Cycle (SDLF)
    • Waterfall
    • V Model
    • Agile
      • Methods
        • Xtreme Programming
          • TDD
          • BDD
        • Scrum
        • Kanban
      • Question
  • Secure Software Development Framework (SSDF)
    • Page 1
  • Source Control
    • Git
    • SVN
    • TFS
  • Integration Systems
    • Stripe
    • Salesforce
    • TaxJar
    • Zendesk
  • Enterprise Service Bus (ESB)
    • Mulesoft
  • Data
    • 5 type of analytics
  • SOFTWARE QUALITY STANDARDS – ISO 5055
    • Standard
    • All about ISO 5055
  • Interview Question
    • Overview
      • Roadmap To Clearing Technical Interview
    • Technical
      • DSA
      • System Design
      • C#
      • React
    • Behavior
    • Question back to the interviewer
  • Roadmap
    • .NET
    • Java
  • English
    • Phát âm ed
    • Many vs much
    • Most vs most of vs almost vs the most
    • Quy tắc thêm s,es vào danh từ và cách phát âm s,es chuẩn xác nhất
  • Those will be seen later
    • Note
    • Interview
  • Programming Language
    • Python
      • Data structure
        • Set
    • Javascript
      • Data Structure
        • Map
    • C#
      • Data Structure
        • Value type & Reference type
        • Using statement
        • HashSet
        • Dictionary
        • Priority Queue
      • Fact
        • Understand about IEnumerable vs. IQueryable vs. ICollection vs. IList
        • 5 things you should know about enums in C#
    • Java
Powered by GitBook
On this page

Last updated 1 year ago

we create those Pods without caring about how much CPU and memory they will need to run or are limited to only how much CPU and memory they can use. chief. But when running in reality, determining the resources of each Pod is very important, it will help our applications achieve good performance when running in the cluster. For example, we have 2 services, one handles notifications, the other handles transactions. We don't want the notify service to run and take up all the resources of the transaction processing service, because the transaction service is more important.

In this article we will see how to configure and manage resource requests and resource limits of a Pod in the most effective way.

Requesting resources

When writing a Pod's configuration, we can add properties to specify the total amount of CPU and memory of a container that it needs to run (called resource requests), and the total amount of CPU and memory that it can only handle. We can consume that much, but we cannot consume more than the total amount we have specified (called the resource limit).

We will specify properties for each container in the Pod, and the resouce requests - resource limits of a Pod will be added up from its containers.

Create Pod with resource requests

Now let's do an example to understand better, create a file named requests-pod.yaml with the following configuration:

In the file above, we use the resources.requests.cpu attribute to specify the amount of CPU this container needs, and resources.requests.memory to specify the amount of memory this container needs. Now we create a Pod and test its CPU with the top command:

The dd command running in the container can consume as many resources as it wants because we have not specified a resources limit. In the example above we see there are 6 cpu, each 12% is 120m, total is 720m.

What do resource requests mean?

If you think that when we specify the resources.requests attribute for the container in the Pod, kubernetes will keep that amount of server resources for the container to run, then that's not true.

Note that one important thing is that when we specify this value, as in the example above, kubernetes will not keep 200m cpu and 10Mi memory of the server for this container to use, but this value will be used during the process. A Pod is scheduled to a worker node. The scheduler will find which worker node still has unallocated CPU greater than 200m and unallocated memory greater than 10Mi to schedule Pod to that worker node. If we do not specify resources.requests , then when the Pod is scheduled to a worker node, the Scheduler will not consider the worker node's CPU and unallocated memory values ​​for the Pod. This means that if our Pod needs 200m CPU to run, but we do not specify it clearly, then a worker node only has 100m CPU, our Pod can also be scheduled to that worker node.

And another important thing is that the CPU and unallocated memory values ​​will be calculated by the Scheduler by subtracting the node's resources from the total resources.requests of the Pod (if any, or if the pod's current CPU if there is no index). resource requests, or the current CPU is larger than the resource requests because we do not use limit, the Scheduler will take the larger value) on a worker node, not the value of the worker's free and unused CPU and memory. node. Even if the worker node's free value meets Pod requests and the unallocated value does not, the Pod will not be scheduled there.

In the illustration above, the Pod will not be deployed to the worker node because the current CPU request is larger than the remaining unallocated CPU of the worker node, even though the actual free CPU is up to 45%. The scheduler will not consider actual free cpu but only unallocated cpu.

How Scheduler uses resource requests to choose the best node for Pod

  • LeastRequestedPriorit: will choose the node with the least total resource request, meaning the most unallocated resources.

  • MostRequestedPriority: will choose the node with the highest total resource request, meaning the least unallocated resource.

The scheduler will be configured to choose one of the two methods above, by default the method used is LeastRequestedPriorit. We can configure Scheduler to use the MostRequestedPriority method instead, use MostRequestedPriority when we want our resources to be used as evenly as possible, very important in a cloud provider environment, we will want to use as few VMs as possible to Cut the cost.

Scheduler in action

Now we will create another pod to see if the Scheduler does it the way we said above. First we will look at the node's capacity.

There are two important properties we need to pay attention to: Capacity and Allocatable, with Capacity being the total resources of the worker node, and Allocatable being the resources that the Pod can use. We will see that it is not equal because there will be a few resources for the system to use. We shouldn't use it all. We have an allocatable cpu of 8 cores = 8000m, and an allocated cpu of 3475m. We will create a Pod that requests 3000m to see if our cpu allocation increases.

If you run kubelet version greater than 1.21, you will receive the following message:

If you encounter this error, create a config file and do not use cli. Now let's describe the node again:

We will see that now our CPU allocation has increased to 6475m. If we create another Pod with a request of 3000m, our Pod will not be able to deploy to the node.

Our Pod requests-pod-3 will be in pending state because it is not deployed to the pod. When we describe the pod, we will see the reason is that no worker node has enough CPU for the Pod:

Limiting resources

We have understood how to use resources requests, now we will see how to use resources limit, to avoid one Pod taking up the resources of other Pods. Create a file named limited-pod.yaml with the following configuration:

In the config file above, we use the resources.limits attribute to specify the resource limit of a container. If we do not specify the request attribute, by default it will be assigned equal to the value of limits. Create file and test:

We will see that above when we have not specified the limit, the cpu core we can use is 6. After we specify, the cpu core we can use is now only 1.

When a container exceeds limit

So what happens when one of our containers uses resources beyond the limit resource we specified. Then there will be two cases:

  • Regarding cpu, when our container needs more than the number of cpu we have specified in the limit, it cannot use more than this cpu, it can only use the cpu we have specified.

QoS classes

Unlike cpu limit, our total memory limit when configuring can exceed 100% of the worker node's memory. So what happens if a Pod runs out of worker node's memory, will that Pod be killed or will another Pod be killed?

For example, we have two Pods, one A with limit 550Mi memory, one B with limit 600Mi memory, our worker node memory only has 1G RAM. Now guy A is running and taking up 500Mi, guy B is running and taking up 400Mi, then guy B is running and taking up 550Mi of memory, the two guys combined are 1050Mi, exceeding the memory of the worker node, while no one is running over the memory. Its limit is over, so who will be killed?

So kubernetes provides us with a way to rate the priority of Pods. Pods with lower priority will be killed first. Quality of Service (QoS) is how kubernetes prioritizes Pods, there are 3 QoS:

  • BestEffort (lowest priority)

  • Burstable

  • Guaranteed (highest priority)

QoS will be assigned to the container, then combining all the QoS of the container we will get the QoS of the Pod.

Determine the QoS of the container

BestEffort is the container with the lowest priority, this QoS class will be assigned to the container without specifying resources requests and limits attributes. If the worker node's memory exceeds 100%, the Pod with class BestEffort will be killed first.

Burstable is a container with medium priority. This QoS class will be assigned to containers that specify each resource request, or specify that the values ​​of the two attributes resources requests and limits are not equal, Pods with class Burstable will be killed. when no more Pods with class BestEffort exist.

Guaranteed is the container with the highest priority, killed last. This QoS class will be assigned to the Pod that:

  • Specify both resources requests and limits in the container. Or specify each resource limit, resource requests will default to the value of resource limits.

  • These two attributes must have equal values.

Determine the Pod's QoS

If all containers have the same QoS class, then that QoS will be the Pod's QoS, otherwise, the QoS will be combined according to the following table:

Understand how Pods are killed when memory exceeds the worker node's limit

As we said above, when the worker node's memory exceeds 100%, the Pod with Qos as BestEffort will be killed first, followed by the Pod with Qos as Burstable, and finally Guaranteed.

How Pod with QoS will be killed

Each of our processes will have an OutOfMemory (OOM) score. When Pods have the same QoS class, the process with higher OOM will be killed first. OOM score will be calculated by the number of memory requests and the number of memory processes currently in use. Whoever is using the higher percentage of memory with the request will be killed first.

Configure default request and limit for namespace

We have learned how to use requests and limits, by specifying properties for each specific container. If we do not specify, the Pod will spend as much as it wants, so it would be good to have a way to configure requests and limits with a default value for a container when we do not specify its requests and limits.

LimitRange resource

Instead of having to configure each container separately, we can create a resource called LimitRange, to specify default requests and limits in a namespace for us.

LimitRange will have two uses, specifying the minimum and maximum of requests and limits, and the default value when we do not specify properties in the container.

Create LimitRange

Now we will create a LimitRange resource, create a file called limits.yaml with the following configuration:

In the config file above, we specify the limit for 3 components: Pod, Container, PersistentVolumeClaim. We specify the Pod's cpu minimun as 50m and memory as 5Mi, maximun as 1 cpu and 1Gi memory. For containers, we specify the default value of the request with the defaultRequest attribute and the default value of limit with the default attribute , and the max and min attributes are similar to those of the Pod. We can also specify a value for storage with type PersistentVolumeClaim.

We create and test whether LimitRange works as we want.

If it prints this error, then our LimitRange is working correctly, we only allow maximun cpu request to be 1 core, above we request 3 cores so we cannot create a Pod.

We check and see that LimitRange has correctly validated the min and max of a Pod that can be created. Now let's check if it specifies default requests and limits values ​​for us.

Check the terminal and we will see that our container has been assigned default requests and limits values. LimitRange already works as we want.

Limit the total number of resources of a namespace

We have seen the convenience when we use LimitRange. But you can notice that LimitRange only limits the resources of an object in a namespace, but cannot limit the total usable resources of a namespace. When working on a project with many different teams, we will want each team to only be able to use the amount of resources we assign to them, this team should not use other teams' resources. To do that, kubernetes provides us with a resource called ResourceQuota.

ResourceQuota

This is a resource that will help us limit the resources of a namespace. When we create a ResourceQuota resource, it will be configured in the Admission Control plugin like LimitRange. When a Pod is created, it must go through this plugin to check whether the Pod is valid or not. whether or not the resource limit we specified in ResourceQuota is used, if so, the API server will return an error.

ResourceQuota not only limits the resource usage of Pods and storage of PersistentVolumeClaims, but can also limit the number of Pods and PersistentVolumeClaims that can be created in a namespace.

ResourceQuota limits cpu and memory

Now we will look at an example to make it easier to understand, create a file named quota-cpu-memory.yaml with the following configuration:

In the config file above, we will specify the total request resource of the default namespace as 400m cpu and 200Mi memory. When we create a Pod, we cannot specify a request larger than this number, and the total resource it uses is limited. is 600M CPU and 500Mi memory. When we create this ResourceQuota, all Pods in the namespace can only use a maximum of 600m CPU and 500Mi memory. For example, if we need to create a Pod with a request of 200m cpu, we can only create a maximum of 3 Pods in the default namespace.

After we create a resource, we can see how many resources have been used within the quota with the describe command:

If we delete all the Pods created above, we will see that all 4 parameters are 0. Now we will create a Pod and check to see if this number increases:

We see that the value here has increased exactly as we want, now we will create a Pod that requires 400m cpu, this time it will report an error:

You will see the error that pods "quota-pod-1" is forbidden: exceeded quota: cpu-and-mem , meaning that Pod quota-pod-1 exceeds the limit of our current ResourceQuota, so the Pod cannot be created. go out.

ResourceQuota limits persistent storage

To limit persistent storage of a namespace, we create a file with the following configuration:

In the config file above, the request limit for all PersistentVolumeClaims in the default namespace is 500Gi. We can also clearly specify the request limit for each specific StorageClass, by prefixing the StorageClass name as follows <storageclass-name>.storageclass.storage.k8s.io/requests.storage.

ResourceQuota limits the number of resources that can be created

Besides resource and storage limits, we can also use ResourceQuota to specify the number of resource objects we can create in a namespace, for example:

In the config file above, we limit the number of pods that can be created in the default namespace to 10, replication controllers to 5, secrets to 10, etc. The resources that ResourceQuota can specify are:

  • Pods

  • ReplicationControllers

  • Secrets

  • ConfigMaps

  • PersistentVolumeClaims

  • Services: can specify the number of LoadBalancer Services and NodePort Services

Quota scope for Pod

For Pod, we can specify whether Quota is applied to it or not based on the following 4 properties:

  • BestEffort: only affects Pods with Qos class BestEffort

  • NotBestEffort: only affects Pods with Qos class Burstable and Guaranteed

  • Terminating: only affects Pods with activeDeadlineSeconds attribute

  • NotTerminated: only affects Pods that do not have the activeDeadlineSeconds attribute

For example:

In the above config file, we can only create 4 pods with Qos class BestEffort and no active deadline attribute specified.

Conclude

So we have learned about how to configure requests and limits for Pod. When running a real application on kubernetes cluster, we need to pay close attention to this index, to help our application run as best as possible. We also know how to use LimitRange to configure default requests and limits for Pods. Using LimitRange will be more convenient when we want all containers in our Pod to have requests and limits. Use ResourceQuota to limit resources for a namespace, dividing resources for each team appropriately. If you have any questions or need further clarification, you can ask in the comment section below.

In the post , we talked about how the Scheduler will filter out the best nodes using an algorithm and then arrange them in order of priority to select the node with the highest priority. Then, resource requests will be used as a criterion to evaluate the priority order for the node, there are two methods: LeastRequestedPriority, MostRequestedPriority.

For memory, it will be different. When our container exceeds the allowed limit, this container will be killed. If we specify the restartPolicy mentioned in as Always or OnFailure, our container will automatically restart. .

Container 1 QoS class
Container 2 QoS class
Pod’s QoS class

When we create LimitRange, it will be configured inside the Admission control plugin that we talked about in .

apiVersion: v1
kind: Pod
metadata:
  name: requests-pod
spec:
  containers:
    - name: main
      image: busybox
      command: ["dd", "if=/dev/zero", "of=/dev/null"]
      resources:
        requests:
          cpu: 200m # The container requests 200 millicores (that is, 1/5 of a single CPU core’s time).
          memory: 10Mi # The container also requests 10 mebibytes of memory.
$ kubectl apply -f requests-pod.yaml
pod/requests-pod created
$ kubectl exec -it requests-pod top
Mem: 8006084K used, 143884K free, 214440K shrd, 74888K buff, 930220K cached
CPU:  7.6% usr 12.9% sys  0.0% nic 73.8% idle  1.1% io  0.0% irq  4.4% sirq
Load average: 3.51 2.65 1.14 8/5061 14
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
    1     0 root     R     1308  0.0   6 12.0 dd if /dev/zero of /dev/null
    8     0 root     R     1316  0.0   1  0.0 top
$ kubectl describe node
...
Capacity:
  cpu:                8
  ephemeral-storage:  263174212Ki
  hugepages-2Mi:      0
  memory:             8149968Ki
  pods:               110
Allocatable:
  cpu:                8
  ephemeral-storage:  242541353378
  hugepages-2Mi:      0
  memory:             8047568Ki
  pods:               110
...
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests
  --------           --------
  cpu                3475m (43%)
  memory             6978796928 (84%)
...
$ kubectl run requests-pod-2 --image=busybox --restart Never --requests='cpu=3000m,memory=20Mi' -- dd if=/dev/zero of=/dev/null
pod/requests-pod-2 created
Flag --requests has been deprecated, has no effect and will be removed in the future.
$ kubectl describe node
...
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests
  --------           --------
  cpu                6475m (80%)
  memory             6999768448 (84%)
...
$ kubectl run requests-pod-3 --image=busybox --restart Never --requests='cpu=3000m,memory=20Mi' -- dd if=/dev/zero of=/dev/null
pod/requests-pod-3 created

$ kubectl get pod
NAME             READY   STATUS    RESTARTS   AGE
requests-pod-2   1/1     Running   0          6m10s
requests-pod-3   0/1     Pending   0          44s
$ kubectl describe pod requests-pod-3
...
Events:
  Type     Reason            Age                 From               Message
  ----     ------            ----                ----               -------
  Warning  FailedScheduling  55s (x3 over 2m2s)  default-scheduler  0/1 nodes are available: 1 Insufficient cpu.
apiVersion: v1
kind: Pod
metadata:
  name: limits-pod
spec:
  containers:
    - name: main
      image: busybox
      command: ["dd", "if=/dev/zero", "of=/dev/null"]
      resources:
        limits:
          cpu: 1000m # The container limits 1 cpu core.
          memory: 20Mi # The container limits 20 mebibytes of memory.
$ kubectl apply -f limited-pod.yaml
pod/limits-pod created

$ kubectl exec -it limits-pod top
Mem: 7462364K used, 687604K free, 174260K shrd, 151972K buff, 1245064K cached
CPU:  6.7% usr 10.8% sys  0.0% nic 78.0% idle  0.4% io  0.0% irq  3.9% sirq
Load average: 2.10 1.31 1.30 4/4106 13
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
    1     0 root     R     1308  0.0   1 12.1 dd if /dev/zero of /dev/null
    7     0 root     R     1316  0.0   4  0.0 top

Best Effort

Best Effort

Best Effort

Best Effort

Burstable

Burstable

Best Effort

Guaranteed

Burstable

Burstable

Burstable

Burstable

Burstable

Guaranteed

Burstable

Guaranteed

Guaranteed

Guaranteed

apiVersion: v1
kind: LimitRange
metadata:
  name: example
spec:
  limits:
    - type: Pod
      min:
        cpu: 50m
        memory: 5Mi
      max:
        cpu: 1
        memory: 1Gi
    - type: Container
      defaultRequest:
        cpu: 100m
        memory: 10Mi
      default:
        cpu: 200m
        memory: 100Mi
      min:
        cpu: 50m
        memory: 5Mi
      max:
        cpu: 1
        memory: 1Gi
      maxLimitRequestRatio:
        cpu: 4
        memory: 10
    - type: PersistentVolumeClaim
      min:
        storage: 1Gi
      max:
        storage: 10Gi
$ kubectl apply -f limits.yaml
limitrange/example created

$ kubectl run requests-pod-big-cpu --image=busybox --requests='cpu=3'
The Pod "requests-pod-big-cpu" is invalid: spec.containers[0].resources.requests: Invalid value: "3": must be less than or equal to cpu limit
$ kubectl run pod-no-setting-resoucre --image=busybox --restart Never -- dd if=/dev/zero of=/dev/null
pod/pod-no-setting-resoucre created

$ kubectl describe pod pod-no-setting-resoucre
Name:         pod-no-setting-resoucre
Namespace:    default
...
Containers:
  pod-no-setting-resoucre:
    Container ID:  docker://9add62820682c8ef4cae6e647b3180b396118cfdfdaac857f3fd396b686e10b2
    Image:         busybox
    ...
    Limits:
      cpu:     200m
      memory:  100Mi
    Requests:
      cpu:        100m
      memory:     10Mi
...
apiVersion: v1
kind: ResourceQuota
metadata:
  name: cpu-and-mem
  namespace: default
spec:
  hard:
    requests.cpu: 400m
    requests.memory: 200Mi
    limits.cpu: 600m
    limits.memory: 500Mi
$ kubectl apply -f quota-cpu-memory.yaml
resourcequota/cpu-and-mem created

$ kubectl describe quota cpu-and-mem
Name:            cpu-and-mem
Namespace:       default
Resource         Used  Hard
--------         ----  ----
limits.cpu       0     600m
limits.memory    0     500Mi
requests.cpu     0     400m
requests.memory  0     200Mi
$ kubectl run quota-pod --image=busybox --restart Never --limits='cpu=300m,memory=200Mi' -- dd if=/dev/zero of=/dev/null
pod/quota-pod created

$ kubectl describe quota cpu-and-mem
Name:            cpu-and-mem
Namespace:       default
Resource         Used   Hard
--------         ----   ----
limits.cpu       300m   600m
limits.memory    200Mi  500Mi
requests.cpu     300m   400m
requests.memory  200Mi  200Mi
$ kubectl run quota-pod-1 --image=busybox --restart Never --limits='cpu=400m,memory=200Mi' -- dd if=/dev/zero of=/dev/null
Error from server (Forbidden): pods "quota-pod-1" is forbidden: exceeded quota: cpu-and-mem, requested: limits.cpu=400m,requests.cpu=400m,requests.memory=200Mi, used: limits.cpu=300m,requests.cpu=300m,requests.memory=200Mi, limited: limits.cpu=600m,requests.cpu=400m,requests.memory=200Mi
apiVersion: v1
kind: ResourceQuota
metadata:
  name: storage
spec:
  hard:
    requests.storage: 500Gi
    ssd.storageclass.storage.k8s.io/requests.storage: 200Gi
    standard.storageclass.storage.k8s.io/requests.storage: 300Gi
apiVersion: v1
kind: ResourceQuota
metadata:
  name: objects
spec:
  hard:
    pods: 10
    replicationcontrollers: 5
    secrets: 10
    configmaps: 10
    persistentvolumeclaims: 4
    services: 5
    services.loadbalancers: 1
    services.nodeports: 2
apiVersion: v1
kind: ResourceQuota
metadata:
  name: besteffort-notterminating-pods
spec:
  scopes:
    - BestEffort
    - NotTerminating
  hard:
    pods: 4
  1. Devops
  2. Kubernetes

Managing and calculating resources used for Pods

PreviousAdditionalNextAutomatic scaling Pods and clusters
  • Requesting resources
  • Limiting resources
  • QoS classes
  • Configure default request and limit for namespace
  • Limit the total number of resources of a namespace
  • Conclude
Kubernetes internals architecture
lesson 12
lesson 11