Installation and Architecture Overview
Core Components
- API Server: Handles cluster operations and user requests
- Controller Manager: Maintains desired pod states and self-healing
- Scheduler: Assigns pods to worker nodes
- etcd: Distributed key-value store for cluster state
Installation Methods
yum: Simple but outdated versions
kubeadm: Recommended for production with network requirements
Minikube: Single-node for development/testing
Manual binaries: Complex but customizable
Source compilation: Advanced method requiring Go environment
Environment Specificasion
System Configuration
hostnamectl set-hostname k8s-control
hostnamectl set-hostname k8s-worker
systemctl disable firewalld --now
setenforce 0
Master Node Setup
yum install -y etcd kubernetes-master
systemctl enable etcd kube-apiserver kube-controller-manager kube-scheduler
systemctl start etcd kube-apiserver
Worker Node Setup
yum install -y kubernetes-node
systemctl enable kubelet kube-proxy
systemctl start kubelet
Container Networking
yum install -y flannel docker
etcdctl set /coreos/network/config '{"Network":"10.100.0.0/16"}'
systemctl restart flannel docker kubelet
Private Registry Configuration
docker run -d -p 5000:5000 --restart=always --name registry registry:2
cat > /etc/docker/daemon.json <<EOF
{"insecure-registries":["192.168.1.101:5000"]}
EOF
systemctl restart docker
Key Features and Resource Types
Kubernetes Capabilities
- Self-healing pod restart and rescheduling
- Horizontal autoscaling based on metrics
- Service discovery with DNS and load balancing
- Rolling updates with automated rollback
Pod Resource Example
apiVersion: v1
kind: Pod
metadata:
name: webserver
labels:
tier: frontend
spec:
containers:
- name: nginx
image: private-registry:5000/nginx:stable
ports:
- containerPort: 8080
ReplicaController Operations
kubectl scale rc frontend --replicas=5
kubectl rolling-update frontend --image=nginx:1.20 --update-period=30s
Deployment Management
kubectl create deployment backend --image=redis:6 --replicas=3
kubectl set image deployment/backend redis=redis:7-alpine
kubectl rollout undo deployment/backend --to-revision=2
Service Exposure
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
type: NodePort
ports:
- port: 80
nodePort: 30080
selector:
app: webserver
Persistent Storage Implementation
Persistent Volume with NFS
apiVersion: v1
kind: PersistentVolume
metadata:
name: database-storage
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
path: /exports/db
server: 192.168.1.100
Data base Deployment with PVC
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
template:
spec:
containers:
- name: database
image: mysql:8.0
volumeMounts:
- name: db-vol
mountPath: /var/lib/mysql
volumes:
- name: db-vol
persistentVolumeClaim:
claimName: mysql-pvc
Horizontal Autoscaling
kubectl autoscale deployment worker --min=2 --max=10 --cpu-percent=80
kubectl get hpa worker -w
Atuoscaling Manifest
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: api-autoscaler
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-server
minReplicas: 3
maxReplicas: 15
targetCPUUtilizationPercentage: 70