zhong (钟鹏群) 1 месяц назад
Родитель
Сommit
1490005d2b

+ 52 - 0
deployments/README.md

@@ -0,0 +1,52 @@
+# Nginx 部署文件
+
+此目录包含用于在 k3s 集群中部署 nginx 的 YAML 文件。
+
+## 文件说明
+
+- `nginx-deployment.yaml`: 包含基本的 nginx 部署和服务定义
+- `nginx-deployment-with-ingress.yaml`: 包含带有 ingress 规则的完整 nginx 应用部署
+- `deploy-nginx.sh`: 用于自动部署 nginx 的脚本
+
+## 部署方法
+
+### 方法 1: 使用基本部署文件
+
+```bash
+kubectl apply -f nginx-deployment.yaml
+```
+
+### 方法 2: 使用带 Ingress 的部署文件
+
+```bash
+kubectl apply -f nginx-deployment-with-ingress.yaml
+```
+
+### 方法 3: 使用部署脚本
+
+```bash
+chmod +x deploy-nginx.sh
+./deploy-nginx.sh
+```
+
+## 访问 nginx 服务
+
+如果使用了 LoadBalancer 类型的服务,可以通过外部 IP 访问:
+
+```bash
+kubectl get svc nginx-service
+```
+
+如果使用了 Ingress,可以通过配置的主机名访问(例如 nginx.local)。
+
+## 查看部署状态
+
+```bash
+kubectl get pods,svc,ingress -l app=nginx
+```
+
+## 删除部署
+
+```bash
+kubectl delete -f nginx-deployment.yaml
+```

+ 27 - 0
deployments/deploy-nginx.sh

@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Script to deploy nginx to k3s cluster
+
+echo "Deploying nginx to k3s cluster..."
+
+# Check if kubectl is available
+if ! command -v kubectl &> /dev/null; then
+    echo "kubectl could not be found. Please install kubectl and configure kubectl config."
+    exit 1
+fi
+
+# Deploy nginx
+echo "Applying nginx deployment..."
+kubectl apply -f nginx-deployment.yaml
+
+# Wait for deployment to be ready
+echo "Waiting for nginx deployment to be ready..."
+kubectl rollout status deployment/nginx-deployment -n default
+
+# Show deployment status
+echo "Nginx deployment status:"
+kubectl get deployments,pods,services -l app=nginx
+
+echo "Nginx deployment completed!"
+echo "To access nginx service, use the external IP from the following command:"
+echo "kubectl get svc nginx-service"

+ 84 - 0
deployments/nginx-deployment-with-ingress.yaml

@@ -0,0 +1,84 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: nginx-app
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: nginx-deployment
+  namespace: nginx-app
+  labels:
+    app: nginx
+spec:
+  replicas: 3
+  selector:
+    matchLabels:
+      app: nginx
+  template:
+    metadata:
+      labels:
+        app: nginx
+    spec:
+      containers:
+      - name: nginx
+        image: registry.cn-hangzhou.aliyuncs.com/zhongpengqun/wanderer:linux-amd64-nginx-stable-alpine-3.23
+        ports:
+        - containerPort: 80
+        resources:
+          requests:
+            memory: "64Mi"
+            cpu: "250m"
+          limits:
+            memory: "128Mi"
+            cpu: "500m"
+        readinessProbe:
+          httpGet:
+            path: /
+            port: 80
+          initialDelaySeconds: 5
+          periodSeconds: 5
+        livenessProbe:
+          httpGet:
+            path: /
+            port: 80
+          initialDelaySeconds: 10
+          periodSeconds: 10
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: nginx-service
+  namespace: nginx-app
+  labels:
+    app: nginx
+spec:
+  selector:
+    app: nginx
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 80
+  type: ClusterIP
+
+---
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: nginx-ingress
+  namespace: nginx-app
+  annotations:
+    kubernetes.io/ingress.class: "traefik"  # Using traefik which is typically available in k3s
+spec:
+  rules:
+  - host: nginx.local
+    http:
+      paths:
+      - path: /
+        pathType: Prefix
+        backend:
+          service:
+            name: nginx-service
+            port:
+              number: 80

+ 44 - 0
deployments/nginx-deployment.yaml

@@ -0,0 +1,44 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: nginx-deployment
+  labels:
+    app: nginx
+spec:
+  replicas: 3
+  selector:
+    matchLabels:
+      app: nginx
+  template:
+    metadata:
+      labels:
+        app: nginx
+    spec:
+      containers:
+      - name: nginx
+        image: nginx:1.21.6
+        ports:
+        - containerPort: 80
+        resources:
+          requests:
+            memory: "64Mi"
+            cpu: "250m"
+          limits:
+            memory: "128Mi"
+            cpu: "500m"
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: nginx-service
+  labels:
+    app: nginx
+spec:
+  selector:
+    app: nginx
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 80
+  type: LoadBalancer