Kubernetes ব্যবহারকারী ম্যানুয়াল

মৌলিক ধারণা

Pod

Pod হলো Kubernetes-এর সবচেয়ে ছোট ডিপ্লয়যোগ্য ইউনিট, যা ক্লাস্টারে চলমান এক বা একাধিক কন্টেইনার প্রতিনিধিত্ব করে। সাধারণত একটি Pod একটি একক কন্টেইনার ধারণ করে, তবে একাধিক দৃঢ়ভাবে সংযুক্ত কন্টেইনারও ধারণ করতে পারে।

Deployment

Deployment স্টেটলেস অ্যাপ্লিকেশন পরিচালনার জন্য ব্যবহৃত হয়, সহজ ডিপ্লয়মেন্ট, স্কেলিং, এবং আপডেটের জন্য ডিক্লারেটিভ আপডেট ক্ষমতা প্রদান করে।

Service

Service Pod-গুলির একটি সেটের জন্য স্থিতিশীল নেটওয়ার্ক এন্ডপয়েন্ট প্রদান করে, Pod IP অ্যাড্রেস পরিবর্তিত হলেও স্থিতিশীলতা বজায় রাখে।

Namespace

Namespace ক্লাস্টার রিসোর্সকে একাধিক লজিক্যাল পার্টিশনে বিভক্ত করে, যা একই ক্লাস্টার শেয়ার করা একাধিক দল বা প্রকল্পের জন্য উপযুক্ত।

সাধারণ কমান্ড

ক্লাস্টার ব্যবস্থাপনা

# View cluster information
kubectl cluster-info

# View nodes
kubectl get nodes

# View all Pods
kubectl get pods --all-namespaces

# View cluster resource usage
kubectl top nodes
kubectl top pods

অ্যাপ্লিকেশন ডিপ্লয়মেন্ট

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

# View Deployments
kubectl get deployments

# Scale
kubectl scale deployment nginx --replicas=3

# Update image
kubectl set image deployment/nginx nginx=nginx:1.21

# Rollback
kubectl rollout undo deployment/nginx

# View rollout status
kubectl rollout status deployment/nginx

সার্ভিস ব্যবস্থাপনা

# Expose a Service
kubectl expose deployment nginx --port=80 --type=LoadBalancer

# View Services
kubectl get services

# Delete Service
kubectl delete service <service-name>

ডিবাগিং

# View Pod logs
kubectl logs <pod-name>

# Execute command in container
kubectl exec -it <pod-name> -- /bin/bash

# Describe resource details
kubectl describe pod <pod-name>

# Port forward for debugging
kubectl port-forward <pod-name> 8080:80

রিসোর্স ম্যানিফেস্ট

Kubernetes YAML ফাইল ব্যবহার করে ডিক্লারেটিভ রিসোর্স ব্যবস্থাপনা সমর্থন করে। এখানে সাধারণ রিসোর্স সংজ্ঞা রয়েছে:

Deployment উদাহরণ

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: my-app:latest
        ports:
        - containerPort: 8080
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
          requests:
            memory: "64Mi"
            cpu: "250m"

Service উদাহরণ

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: ClusterIP

ConfigMap উদাহরণ

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  database_url: "postgres://db:5432/myapp"
  cache_enabled: "true"

Secret উদাহরণ

apiVersion: v1
kind: Secret
metadata:
  name: my-secret
type: Opaque
stringData:
  username: admin
  password: changeme

অ্যাপ্লিকেশন লাইফসাইকেল ব্যবস্থাপনা

অ্যাপ্লিকেশন ডিপ্লয় করা

# Deploy using YAML file
kubectl apply -f deployment.yaml

# View deployment status
kubectl get pods -l app=my-app

অ্যাপ্লিকেশন আপডেট করা

# Update image version
kubectl set image deployment/my-app my-app=my-app:v2

# View update progress
kubectl rollout status deployment/my-app

রোলব্যাক করা

# Rollback to previous version
kubectl rollout undo deployment/my-app

# Rollback to specific revision
kubectl rollout undo deployment/my-app --to-revision=2

# View revision history
kubectl rollout history deployment/my-app

স্কেলিং

# Manual scaling
kubectl scale deployment my-app --replicas=5

# Auto-scaling (HPA)
kubectl autoscale deployment my-app --min=2 --max=10 --cpu-percent=80

স্টোরেজ ব্যবস্থাপনা

PersistentVolume তৈরি করা

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  storageClassName: standard
  hostPath:
    path: /data/my-app

PersistentVolumeClaim তৈরি করা

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

Pod-এ PVC ব্যবহার করা

apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  containers:
  - name: my-app
    image: my-app
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: my-pvc

কনফিগারেশন ব্যবস্থাপনা

ConfigMap ব্যবহার করা

# Create ConfigMap from file
kubectl create configmap my-config --from-file=config.properties

# Create from env file
kubectl create configmap my-config --from-env-file=env.properties

# Use in Pod
kubectl apply -f pod-with-configmap.yaml

Secret ব্যবহার করা

# Create Secret from file
kubectl create secret generic my-secret --from-file=credentials.json

# Use in Pod
kubectl apply -f pod-with-secret.yaml

রিসোর্স কোটা এবং সীমা

ResourceQuota

apiVersion: v1
kind: ResourceQuota
metadata:
  name: my-quota
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 8Gi
    limits.cpu: "8"
    limits.memory: 16Gi
    pods: "20"

LimitRange

apiVersion: v1
kind: LimitRange
metadata:
  name: my-limits
spec:
  limits:
  - max:
      cpu: "2"
      memory: 1Gi
    min:
      cpu: 100m
      memory: 128Mi
    default:
      cpu: 500m
      memory: 512Mi
    defaultRequest:
      cpu: 200m
      memory: 256Mi
    type: Container

মনিটরিং এবং লগিং

মনিটরিং

# View resource usage with kubectl top
kubectl top nodes
kubectl top pods

# View detailed status
kubectl describe node <node-name>
kubectl describe pod <pod-name>

লগিং

# View Pod logs
kubectl logs my-app-pod

# Follow logs in real-time
kubectl logs -f my-app-pod

# View logs of previous container instance
kubectl logs --previous my-app-pod

সেরা অনুশীলন

  1. ইনফ্রাস্ট্রাকচার পরিচালনার জন্য ডিক্লারেটিভ কনফিগারেশন ব্যবহার করুন
  2. উপযুক্ত রিসোর্স সীমা এবং রিকোয়েস্ট সেট করুন
  3. লেবেল ব্যবহার করে রিসোর্স সংগঠিত করুন
  4. নিয়মিত অব্যবহৃত রিসোর্স পরিষ্কার করুন
  5. বিভিন্ন পরিবেশ বিচ্ছিন্ন করতে Namespace ব্যবহার করুন
  6. হেলথ চেক প্রোব কনফিগার করুন
  7. অনুমতি নিয়ন্ত্রণ করতে RBAC ব্যবহার করুন
  8. নিয়মিত etcd ডেটা ব্যাকআপ করুন