目录
- 概述
- 实践
- 部署openrestry
- 脚本
- 效果
- 验证
概述
此篇将在 k8s
运行起一个 openrestry
环境:k8s:1.27.9 ,openrestry(docker镜像版本): 1.25.x ,k8s
与 ingress
请参考我的其它文章
离线镜像包请参考:openrestry-1.25.x离线镜像安装包
实践
部署openrestry
[root@hadoop02 ~]# cd openregisty/
[root@hadoop02 openregisty]# ls
ingress-all.yaml openregisty-dp-svc.yaml openregisty-dp.yaml
[root@hadoop02 openregisty]# kubectl create -f openregisty-dp.yaml
persistentvolumeclaim/openresty-nfs created
deployment.apps/openresty created
[root@hadoop02 openregisty]# kubectl create -f openregisty-dp-svc.yaml
service/openresty-svc created
[root@hadoop02 openregisty]# kubectl create -f ingress-all.yaml
Error from server (AlreadyExists): error when creating "ingress-all.yaml": ingresses.networking.k8s.io "ingress-nacos" already exists
[root@hadoop02 openregisty]# kubectl create -f ingress-all.yaml
ingress.networking.k8s.io/ingress-all created
脚本
# openregisty-dp.yaml
# pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: openresty-nfs
namespace: default
labels:
pvc: openresty-nfs
spec:
resources:
requests:
storage: 2048Mi
accessModes:
- ReadWriteMany
storageClassName: managed-nfs-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: openresty
spec:
# 根据需求设置副本数量
replicas: 1
selector:
matchLabels:
app: openresty
template:
metadata:
labels:
app: openresty
spec:
containers:
- name: openresty
image: harbor.easzlab.io.local:8443/library/openresty:1.25.3.1-4-alpine-fat
ports:
- containerPort: 80
name: http
- containerPort: 443
name: https
volumeMounts:
- mountPath: /usr/local/openresty/nginx/conf/lua-scripts
name: lua-scripts-volume
# command: ["/bin/bash", "-c"]
# args: ["exec /usr/local/openresty/bin/openresty -g 'daemon off;'"]
volumes:
- name: lua-scripts-volume
persistentVolumeClaim:
claimName: openresty-nfs
# openregisty-dp-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: openresty-svc
spec:
selector:
app: openresty
ports:
- name: http
port: 80
targetPort: 80
- name: https
port: 443
targetPort: 443
type: LoadBalancer # 或者 NodePort
#ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-all
namespace: default
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
# kubernetes.io/ingress.class: nginx
spec:
ingressClassName: nginx
rules:
- host: "all.fun.com"
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: openresty-svc
port:
number: 80
效果
链接地址:http://all.fun.com/
验证
验证数据是否持久化
/usr/local/openresty/nginx