💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## 创建测试应用 ```shell cat > nginx.yaml <<-EOF apiVersion: apps/v1 kind: Deployment metadata: name: my-nginx spec: selector: matchLabels: app: my-nginx template: metadata: labels: app: my-nginx spec: containers: - name: my-nginx image: nginx resources: limits: memory: "200Mi" cpu: "500m" requests: memory: "100Mi" cpu: "100m" ports: - name: web containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: nginx-service spec: selector: app: my-nginx ports: - port: 80 targetPort: web EOF ``` ## 启动应用 ```shell $ kubectl apply -f nginx.yaml deployment.apps/my-nginx created service/nginx-service created $ kubectl get pod -owide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES my-nginx-759cf4d696-vkj4q 1/1 Running 0 4m10s 20.0.85.199 k8s-node01 <none> <none> ``` ## 编写ingress资源 ```shell $ cat > nginx-ingress.yaml <<-EOF apiVersion: extensions/v1beta1 kind: Ingress metadata: name: nginx-ingress labels: name: nginx-ingress spec: ingressClassName: nginx rules: - host: www.ecloud.com http: paths: - path: / backend: serviceName: nginx-service servicePort: 80 EOF ``` ## 创建ingress资源 ```shell $ kubectl apply -f nginx-ingress.yaml ingress.extensions/nginx-ingress created $ kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE nginx-ingress <none> www.ecloud.com 192.168.31.103,192.168.31.79 80 21s ``` ## 验证 ```shell $ echo '192.168.31.103 www.ecloud.com' >> /etc/hosts $ curl www.ecloud.com <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> ``` > 可以通过 `keepalived` + `LVS` 高可用,使用 `VIP` 做域名解析。这里就不实现了。