Kubernetes Summary for Basic Usage
1. What and Why
Kubernetes (often abbreviated as K8s) is a powerful container orchestration platform that has become the de facto standard for managing containerized applications in production environments. Here are some key reasons why Kubernetes is widely used and considered essential in modern software development:
Container Orchestration: Kubernetes provides a robust framework for orchestrating and managing containerized applications. It automates deployment, scaling, load balancing, and self-healing of containers, making it easier to run and maintain complex applications.
Portability: Kubernetes abstracts away the underlying infrastructure, allowing you to run applications consistently across various environments, including on-premises data centers, public clouds (e.g., AWS, Azure, Google Cloud), and hybrid environments. This portability reduces vendor lock-in and provides flexibility.
Scalability: Kubernetes can automatically scale your application up or down based on demand. It ensures that your application can handle increased traffic without manual intervention, improving performance and resource utilization.
High Availability: Kubernetes offers built-in support for high availability. It can distribute your application across multiple nodes (servers) and recover from failures, ensuring that your application remains accessible even when some components fail.
Resource Management: Kubernetes allows you to allocate resources (CPU, memory, storage) to containers and applications, ensuring efficient utilization of resources. This prevents one application from starving others of resources.
Service Discovery and Load Balancing: Kubernetes provides service discovery and load balancing out of the box. It manages network traffic, automatically routing requests to the appropriate containers or pods.
Rolling Updates and Rollbacks: Kubernetes simplifies the process of rolling out updates to your applications. It allows you to perform updates without downtime and provides the ability to roll back to a previous version if issues arise.
Secrets and Configuration Management: Kubernetes provides a secure way to manage sensitive data, such as API keys and passwords, through Secrets. It also offers ConfigMaps for managing configuration settings separately from application code.
Ecosystem and Extensibility: Kubernetes has a large and active community, which has led to a rich ecosystem of extensions and tools. You can extend Kubernetes’ functionality through custom resources and operators to fit your specific requirements.
DevOps and CI/CD Integration: Kubernetes integrates seamlessly with DevOps practices and CI/CD pipelines. You can use tools like Helm and Jenkins to automate application deployments and updates.
Observability: Kubernetes offers built-in monitoring and logging capabilities. You can integrate it with popular observability tools like Prometheus and Grafana to gain insights into your application’s performance.
Cost Efficiency: Kubernetes helps optimize resource usage, which can lead to cost savings in cloud environments by preventing over-provisioning and allowing for better resource allocation.
In summary, Kubernetes simplifies the management of containerized applications at scale, making it an essential tool for organizations adopting microservices architecture, cloud-native development, and containerization. Its flexibility, scalability, and extensive ecosystem have made it a crucial part of modern software development and deployment workflows.
2. Important Concepts
- Node: virtual or physical machine;
- Pod: smallest unit of k8s, abstraction of container, has its own IP address;
- Service: permanent IP address, internal service for pods, external service for users;
- Ingress: external service for users, can be used to do load balancing;
- ConfigMap: some configuration which don’t need to be encrypted live here;
- Secret: some configuration which need to be encrypted live here;
- Volume: persistent storage;
- Deployment: for stateless app;
- StatefulSet: for stateful apps or databases;
3. Important file
Our example has a wep app and mongo database.
config.yaml
1 | apiVersion: v1 |
secret.yaml
1 | apiVersion: v1 |
You can use echo -n <content> | base64
to get easily encrypted content.
mongo.yaml
1 | apiVersion: apps/v1 |
Label is used to manage several services or pods with different names but same label.
1 | env: |
The section above can be used to set environment variables of pods in order to make some configuations.
webapp.yaml
1 | apiVersion: apps/v1 |
---
can be used to split different services’ deployment.
4. Some Important Commands
start Minikube and check status
1 | minikube start --vm-driver=hyperkit |
get minikube node’s ip address
1 | minikube ip |
get basic info about k8s components
1 | kubectl get node |
get extended info about components
1 | kubectl get pod -o wide |
get detailed info about a specific component
1 | kubectl describe svc {svc-name} |
get application logs
1 | kubectl logs {pod-name} |
stop your Minikube cluster
1 | minikube stop |
About this Post
This post is written by Chen Li, licensed under CC BY-NC 4.0.