k8s部署nginx+NFS+SSL
k8s部署nginx+NFS+SSL
nginx使用NFS 挂载本地
参考大神:https://blog.csdn.net/weixin_44020899/article/details/107294811
- 创建NFS
- 服务端安装
安装插件
yum install -y nfs-common nfs-utils rpcbind
创建挂载地址
mkdir /nfs
chown nfsnobody /nfs/
配置
vim /etc/exports
/nfs 192.168.0.0/24(rw,no_root_squash,sync)
加载配置
exportfs -r
启动:要注意启动顺序是rpcbind再是nfs,重启需要用到
systemctl start rpcbind && systemctl enable rpcbind
systemctl start nfs && systemctl enable nfs
测试
showmount -e 192.168.0.27
- 客户端安装:
yum install -y nfs-utils rpcbind
systemctl start nfs-utils.service rpcbind.service
测试
showmount -e 192.168.0.27
注意点:
nginx部署前可以启动一个不挂在本地的pod,再压缩容器路径/etc/nginx。kubectl cp传到/nfs/nginx下,修改自定义的内容。
因为没有初始文件容器起不来,需要注意。
- nginx部署
- 创建pv和pvc
cat pvc.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: volume-nginx
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: storage-nginx
nfs:
path: /nfs/nginx/ #挂载路径
server: 192.168.0.27
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claim-nginx
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: storage-nginx
创建
kubectl apply -f nginx-svc.yaml
- 创建pod
cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- ports:
- containerPort: 80
name: nginx
image: nginx:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /etc/nginx/
name: nfs-nginx
volumes:
- metadata:
name: nfs-nginx
persistentVolumeClaim:
claimName: claim-nginx
replicas: 2
kubectl apply -f nginx-deploy.yaml
- 创建svc暴露端口
cat nginx-svc.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx
name: nginx-svc
spec:
ports:
- port: 80
name: server
nodePort: 30320 #固定映射端口
targetPort: 80
protocol: TCP
selector:
app: nginx
type: NodePort
kubectl apply -f nginx-svc.yaml
总的看一下
- 测试
访问http://192.168.0.27:30320/
- 域名映射
整体思路是:
- 本地安装nginx
准备
mkdir /usr/local/nginx
cd /usr/local/nginx
下载
wget http://nginx.org/download/nginx-1.20.1.tar.gz
安装依赖
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc-c++
安装(需要提前准备好需要使用的模块)
./configure --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --prefix=/usr/local/nginx/
make && make install
修改nginxserver配置
upstream registry-backend {
server 10.1.6.108:31320 weight=6 fail_timeout=30s;
server 10.1.213.43:31320 weight=4 fail_timeout=30s;
}
修改文件后重启
kubectl rollout restart -n default deployment nginx
重启之后podIP会变,但是svc服务的IP是不会变的。
启动
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
此处就大功告成了。
研究最深的就是如何ssl映射到容器,网上找了一大堆。
后来发现还是要本地装nginx来进行映射。
当然云环境可以直接添加外网IP进行映射。
更多推荐
所有评论(0)