Update k8s-en.md

pull/8/head
pig6z2klp 5 months ago
parent 9b4149c43e
commit 502d9389a6

@ -28,7 +28,10 @@ Before you begin, please ensure you have the following:
We recommend deploying all DjangoBlog-related resources in a dedicated namespace for better management.
```bash
# Create a namespace named 'djangoblog'
# 创建一个名为'djangoblog'的命名空间namespace
# 命名空间用于在 Kubernetes 集群中隔离不同的应用或环境(如开发、测试、生产)
# 此处创建'djangoblog'命名空间,通常用于部署与 djangoblog 应用相关的资源
# 后续部署的 Pod、Service 等资源可指定在此命名空间下,避免与其他应用资源冲突
kubectl create namespace djangoblog
```
@ -37,16 +40,26 @@ kubectl create namespace djangoblog
This setup uses Local Persistent Volumes. You need to create the data storage directories on a node within your cluster (the default is the `master` node in `pv.yaml`).
```bash
# Log in to your master node
# 通过SSH登录到主节点master node
# user为登录用户名master-node为主节点的地址可是IP或域名
ssh user@master-node
# Create the required storage directories
# 创建所需的存储目录使用sudo获取管理员权限
# -p 选项确保在父目录不存在时自动创建,避免报错
# 用于数据库如MySQL的本地存储目录
sudo mkdir -p /mnt/local-storage-db
# 用于djangoblog应用的本地存储目录
sudo mkdir -p /mnt/local-storage-djangoblog
# 通用资源存储目录
sudo mkdir -p /mnt/resource/
# 用于Elasticsearch的本地存储目录
sudo mkdir -p /mnt/local-storage-elasticsearch
# Log out from the node
# 从节点退出,返回本地终端
exit
```
**Note**: If you wish to store data on a different node or use different paths, you must modify the `nodeAffinity` and `local.path` settings in the `deploy/k8s/pv.yaml` file.
@ -54,13 +67,16 @@ exit
After creating the directories, apply the storage-related configurations:
```bash
# Apply the StorageClass
# 应用StorageClass配置存储类用于定义持久化存储的类型和属性
# StorageClass用于动态供应持久卷PV简化存储管理
kubectl apply -f deploy/k8s/storageclass.yaml
# Apply the PersistentVolumes (PVs)
# 应用持久卷PersistentVolumes, PVs配置
# PV是集群中的一块存储资源由管理员预先创建或通过StorageClass动态生成
kubectl apply -f deploy/k8s/pv.yaml
# Apply the PersistentVolumeClaims (PVCs)
# 应用持久卷声明PersistentVolumeClaims, PVCs配置
# PVC是用户对存储资源的请求用于绑定PV并为Pod提供持久化存储
kubectl apply -f deploy/k8s/pvc.yaml
```
@ -73,10 +89,12 @@ Before deploying the application, you need to edit the `deploy/k8s/configmap.yam
- `DJANGO_MYSQL_PASSWORD` and `MYSQL_ROOT_PASSWORD`: Change to your own secure database password.
```bash
# Edit the ConfigMap file
# 使用vim编辑器编辑ConfigMap配置文件
# ConfigMap用于存储非敏感的配置数据供Pod中的容器使用
vim deploy/k8s/configmap.yaml
# Apply the configuration
# 应用ConfigMap配置到Kubernetes集群
# 执行后配置数据将被创建或更新供相关资源如Pod引用
kubectl apply -f deploy/k8s/configmap.yaml
```
@ -85,10 +103,12 @@ kubectl apply -f deploy/k8s/configmap.yaml
Now, we can deploy all the core services.
```bash
# Deploy the Deployments (DjangoBlog, MySQL, Redis, Nginx, ES)
# 部署 Deployment 资源包含DjangoBlog应用、MySQL数据库、Redis缓存、Nginx服务器、Elasticsearch搜索引擎
# Deployment 用于定义Pod的期望状态负责创建和管理Pod支持滚动更新等功能
kubectl apply -f deploy/k8s/deployment.yaml
# Deploy the Services (to create internal endpoints for the Deployments)
# 部署 Service 资源为上述Deployment创建内部访问端点
# Service 提供固定的访问地址实现Pod的负载均衡和服务发现即使Pod重建IP变化也能通过Service稳定访问
kubectl apply -f deploy/k8s/service.yaml
```
@ -103,7 +123,10 @@ kubectl get pods -n djangoblog -w
Finally, expose the Nginx service to external traffic by applying the `Ingress` rule.
```bash
# Apply the Ingress rule
# 应用Ingress规则配置
# Ingress用于管理Kubernetes集群外部访问集群内部服务的规则如HTTP/HTTPS路由
# 该配置文件deploy/k8s/gateway.yaml定义了外部请求如何映射到集群内的服务如通过域名路由到对应的Service
# 执行后Ingress控制器将根据规则处理外部流量实现对集群内服务的访问
kubectl apply -f deploy/k8s/gateway.yaml
```
@ -118,23 +141,32 @@ kubectl get ingress -n djangoblog
Similar to the Docker deployment, you need to get a shell into the DjangoBlog application Pod to perform database initialization and create a superuser on the first run.
```bash
# First, get the name of a djangoblog pod
# 首先获取djangoblog相关Pod的名称
# -n djangoblog指定在'djangoblog'命名空间中查询
# grep djangoblog筛选出包含'djangoblog'关键词的Pod即目标应用的Pod
kubectl get pods -n djangoblog | grep djangoblog
# Exec into one of the Pods (replace [pod-name] with the name from the previous step)
# 进入其中一个Pod的交互式终端将[pod-name]替换为上一步获取的Pod名称
# -it以交互式终端模式进入Pod
# -n djangoblog指定目标Pod所在的命名空间
# -- bash在Pod内启动bash shell
kubectl exec -it [pod-name] -n djangoblog -- bash
# Inside the Pod, run the following commands:
# Create a superuser account (follow the prompts)
# 在Pod内部运行以下命令
# 创建超级用户账号(按照提示输入用户名、邮箱和密码)
# 超级用户用于登录Django管理后台拥有最高权限
python manage.py createsuperuser
# (Optional) Create some test data
# (可选)创建一些测试数据
# 用于快速填充数据库,方便测试应用功能
python manage.py create_testdata
# (Optional, if ES is enabled) Create the search index
# 可选如果启用了Elasticsearch创建搜索索引
# 初始化或更新Elasticsearch的搜索索引确保搜索功能可用
python manage.py rebuild_index
# Exit the Pod
# 退出Pod的终端返回本地命令行
exit
```

Loading…
Cancel
Save