Kubernetes Basics: Orchestrating Containers at Scale

Kubernetes is the industry-standard container orchestration platform. It automates deployment, scaling, and management of containerized applications across clusters of hosts.

## Core Concepts

- **Pods**: Smallest deployable units
- **Services**: Networking and load balancing
- **Deployments**: Declarative updates for Pods
- **ConfigMaps/Secrets**: Configuration management
- **Namespaces**: Virtual clusters

## Basic Commands

```bash
# Get cluster info
kubectl cluster-info

# List nodes
kubectl get nodes

# Create deployment
kubectl create deployment nginx --image=nginx

# Scale deployment
kubectl scale deployment nginx --replicas=3

# Expose service
kubectl expose deployment nginx --port=80 --type=NodePort
```

## Deployments

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
 name: webapp
spec:
 replicas: 3
 selector:
   matchLabels:
     app: webapp
 template:
   metadata:
     labels:
       app: webapp
   spec:
     containers:
     - name: webapp
       image: nginx:latest
       ports:
       - containerPort: 80
```

## Services

```yaml
apiVersion: v1
kind: Service
metadata:
 name: webapp-service
spec:
 selector:
   app: webapp
 ports:
 - port: 80
   targetPort: 80
 type: LoadBalancer
```

## ConfigMaps

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
 name: app-config
data:
 database_url: "postgres://db:5432"
 cache_enabled: "true"
```

## Health Checks

```yaml
livenessProbe:
 httpGet:
   path: /health
   port: 8080
 initialDelaySeconds: 30
 periodSeconds: 10

readinessProbe:
 httpGet:
   path: /ready
   port: 8080
 initialDelaySeconds: 5
 periodSeconds: 5
```

## Resource Limits

```yaml
resources:
 requests:
   memory: "128Mi"
   cpu: "250m"
 limits:
   memory: "512Mi"
   cpu: "500m"
```

## Conclusion

Kubernetes simplifies container orchestration at scale. Start with Deployments and Services, then explore advanced features like Helm charts and Operators.

评论
暂无评论