服务器搭建系列之3:k8s安装nginx和可视化编辑工具nginxWebUI,2022最新版本

准备以下文件:

Dockerfile

FROM cym1102/nginxwebui:latest

deploy.yaml

需要自行修改命名空间,服务名等

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nginxwebui
  namespace: fandai
spec:
  replicas: 1
  serviceName: nginxwebui
  selector:
    matchLabels:
      app: nginxwebui
  template:
    metadata:
      labels:
        app: nginxwebui
    spec:
      nodeName: fandai-master  #需要指定节点名称
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet  #让nginx可以访问k8s的网络
      containers:
        - name: nginxwebui
          image: registry.cn-qingdao.aliyuncs.com/fandai/nginxwebui
          resources:
            limits:
              memory: "300Mi"
            requests:
              memory: "300Mi"
          env:
            - name: BOOT_OPTIONS
              value: "--server.port=8080 \
                      --project.home=/home/nginxWebUI/ \
                      --spring.database.type=mysql \
                      --spring.datasource.url=jdbc:mysql://mysql-ip:3306/nginx \
                      --spring.datasource.username=root \
                      --spring.datasource.password=root"
          volumeMounts:
            - name: nginx
              mountPath: /home/nginxWebUI
              subPath: nginx
            - name: logs
              mountPath: /home/nginxWebUI/log
              subPath: nginx
      volumes:
        - name: nginx
          persistentVolumeClaim:
            claimName: nginx-data
            readOnly: false
        - name: logs
          persistentVolumeClaim:
            claimName: nginx-logs
            readOnly: false
---
apiVersion: v1
kind: Service
metadata:
  name: nginxwebui
  namespace: fandai
spec:
  selector:
    app: nginxwebui
  type: ClusterIP
  clusterIP: None

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-data
  namespace: fandai
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: fandai-nfs-data
  resources:
    requests:
      storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-logs
  namespace: fandai
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: fandai-nfs-logs
  resources:
    requests:
      storage: 5Gi

run.sh

#!/bin/bash
docker login --username=username registry.cn-qingdao.aliyuncs.com -p password
docker build -t registry.cn-qingdao.aliyuncs.com/fandai/nginxwebui:latest .
docker push registry.cn-qingdao.aliyuncs.com/fandai/nginxwebui:latest
kubectl apply -f pvc.yaml
kubectl delete -f deploy.yaml
kubectl apply -f deploy.yaml

以上文件放到同一个目录
执行sh run.sh
部署完成后通过服务器ip:8080访问nginxWebUi

使用nginxWebUI为可视化工具配置域名

服务器搭建系列之3:k8s安装nginx和可视化编辑工具nginxWebUI,2022最新版本_第1张图片
服务器搭建系列之3:k8s安装nginx和可视化编辑工具nginxWebUI,2022最新版本_第2张图片

服务器搭建系列之3:k8s安装nginx和可视化编辑工具nginxWebUI,2022最新版本_第3张图片

你可能感兴趣的:(nginx,服务器,java)