Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Kubernetes Setup and Fundamental Resource Management

Tech May 12 3

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
Tags: Kubernetes

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.