k8s搭建nginx代理前端页面
#树结构
[root@k8s-master nginx]# tree -L 2
.
├── conf
│ └── default.conf
├── work
│ ├── device-h5
│ ├── operation
│ ├── printm
│ ├── printus
│ └── wprintorder
└── yaml
├── nginx-pvc.yaml
├── nginx-pv.yaml
└── nginx.yaml
8 directories, 4 files
[root@k8s-master nginx]# ll
总用量 0
drwxr-xr-x 2 root root 26 9月 5 11:00 conf
drwxr-xr-x 7 root root 88 9月 5 10:05 work
drwxr-xr-x 2 root root 67 9月 5 10:44 yaml
#配置harbor
kubectl create secret docker-registry harbor \
--docker-server=192.168.11.11 \
--docker-username=admin \
--docker-password=123456 \
kubectl get secrets -n work
NAME TYPE DATA AGE
default-token-xcbc4 kubernetes.io/service-account-token 3 30h
harbor kubernetes.io/dockerconfigjson 1 49s
#
#
spec:
containers:
- name:
image: 192.168.11.11/nginx:1.8
imagePullSecrets:
- name: harbor
[root@k8s-master nginx]# cat yaml/nginx-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nginx-pv
namespace: work
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
storageClassName: nginx-pv
nfs:
path: /usr/local/work/work/nginx/work
server: 192.168.2.249
[root@k8s-master nginx]# cat yaml/nginx-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nginx-pvc
namespace: work
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
storageClassName: nginx-pv
[root@k8s-master nginx]# cat yaml/nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-web
namespace: work
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
hostNetwork: true
containers:
- name: nginx
image: nginx:1.18
ports:
- containerPort: 80
volumeMounts:
- name: work
mountPath: /work
- name: nginx-conf
mountPath: /etc/nginx/conf.d
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 15
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 15
volumes:
- name: work
persistentVolumeClaim:
claimName: nginx-pvc
- name: nginx-conf
configMap:
name: nginx-conf
kubectl create cm -n work nginx-conf --from-file=conf/default.conf
cat conf/default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /printus {
add_header X-Xss-Protection "1;mode=block";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options: SAMEORIGIN;
alias /work/printus;
index index.html index.htm;
try_files $uri $uri/ /printus/index.html;
}
location /wprintorder {
add_header X-Xss-Protection "1;mode=block";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options: SAMEORIGIN;
alias /work/wprintorder;
index index.html index.htm;
try_files $uri $uri/ /wprintorder/index.html;
}
location /operation {
add_header X-Xss-Protection "1;mode=block";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options: SAMEORIGIN;
alias /work/operation;
index index.html index.htm;
try_files $uri $uri/ /operation/index.html;
}
location /printm {
add_header X-Xss-Protection "1;mode=block";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options: SAMEORIGIN;
alias /work/printm;
index index.html index.htm;
try_files $uri $uri/ /printm/index.html;
}
location /device-h5 {
add_header X-Xss-Protection "1;mode=block";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options: SAMEORIGIN;
alias /work/device-h5;
index index.html index.htm;
try_files $uri $uri/ /device-h5/index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}