K8s easy và dễ hiểu

🧭 Sơ đồ minh họa Kubernetes đơn giản

+------------------------------+
|        Kubernetes Cluster    |
|                              |
|  +--------+   +-----------+  |
|  | Node 1 |   |  Node 2   |  |
|  +--------+   +-----------+  |
|     |               |        |
|  +-------+      +-------+    |
|  |  Pod  |      |  Pod  |    |
|  | nginx |      | redis |    |
|  +-------+      +-------+    |
|                              |
+------------------------------+

📄 YAML chạy 1 Pod đơn giản (nginx)

Tạo file tên nginx-pod.yaml với nội dung:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-demo
spec:
  containers:
    - name: nginx
      image: nginx:1.25
      ports:
        - containerPort: 80

🚀 Chạy thử với Minikube

# 1. Khởi động Minikube
minikube start

# 2. Áp dụng file YAML
kubectl apply -f nginx-pod.yaml

# 3. Kiểm tra pod đã chạy chưa
kubectl get pods

# 4. Xem chi tiết pod
kubectl describe pod nginx-demo

# 5. Truy cập vào pod
kubectl exec -it nginx-demo -- /bin/bash
# 1. Khởi động Minikube
minikube start --driver=docker

# 2. Check node 
kubectl get nodes

# 3. Check pods
kubectl get pods -A

# 4. Áp dụng file YAML
kubectl apply -f nginx-pod.yaml

# 5. Kiểm tra pod đã chạy chưa
kubectl get pods

# 6. Xem chi tiết pod
kubectl describe pod nginx-demo

# 7. Truy cập vào pod
kubectl exec -it nginx-demo -- /bin/bash

🌐 Truy cập nginx từ máy bạn

Expose port tạm thời để duyệt trình duyệt:

kubectl port-forward pod/nginx-demo 8080:80
kubectl port-forward pod/nginx-demo 8080:80

→ Truy cập tại: http://localhost:8080

Last updated

Was this helpful?