K8S应用笔记 —— 部署Nginx服务发布前端项目(PV、PVC、Deployment、Service、Ingress )

K8S应用笔记 —— 部署Nginx服务发布前端项目(PV、PVC、Deployment、Service、Ingress )在 K8S 集群上通过部署 Nginx 服务发布前端项目 其中 前端项目发布文件通过 PV 和 PVC 存储在 NFS 上实现多 Pod 持久化和共享 将 Nginx 服务配置文件存储至 K8S 的 configmap 中 将阿里云证书文件存储至 K8S 的 secret 中 通过 Ingress 设置证书 并将 Nginx 服务暴露到集群外部 nginxdeploym

一、需求描述

K8S集群上通过部署Nginx服务发布前端项目,其中:

  • 前端项目发布文件通过PVPVC存储在NFS上实现多Pod持久化和共享
  • Nginx服务配置文件存储至 K8Sconfigmap
  • 将阿里云证书文件存储至K8Ssecret
  • 通过Ingress设置证书,并将Nginx服务暴露到集群外部

二、创建NFS存储

创建NFS存储主要是为了给Nginx服务提供稳定的后端存储,当NginxPod重启或迁移、扩容后,依然能获得原先的数据。这里,我们先要先创建NFS,然后通过使用PVNginx挂载一个远程的NFS路径。

2.1 安装配置NFS服务端

由于硬件资源有限,我在k8s-master上搭建。执行如下命令安装NFSrpcbind

yum -y install nfs-utils rpcbind 

其中,NFS依靠远程过程调用(RPC)在客户端和服务器端路由请求,因此需要安装rpcbind服务。

执行命令 vim /etc/exports,创建 exports 文件,文件内容如下:

/root/nfs_root/ *(insecure,rw,sync,no_root_squash) 

执行以下命令,启动 nfs 服务

# 创建共享目录,如果要使用自己的目录,请替换本文档中所有的 /root/nfs_root/ mkdir /root/nfs_root systemctl enable rpcbind systemctl enable nfs-server systemctl start rpcbind systemctl start nfs-server 

检查配置是否生效

exportfs 
# 输出结果如下所示 /root/nfs_root /root/nfs_root 

2.2 安装配置NFS客户端

注意事项:

  • 如:服务器端防火墙开启,需开放1116628758922049tcp / udp 访问,否则远端客户无法连接。

我在k8s-work1上执行以下命令安装 NFS客户端所需的软件包

yum install -y nfs-utils 

执行以下命令检查 NFS服务器端是否有设置共享目录

# showmount -e $(nfs服务器的IP) showmount -e 192.168.0.50 # 输出结果如下所示 Export list for 192.168.0.50 /root/nfs_root * 

执行以下命令挂载 NFS服务器上的共享目录到本机路径 /root/nfsmount

mkdir /root/nfsmount # mount -t nfs $(nfs服务器的IP):/root/nfs_root /root/nfsmount mount -t nfs 192.168.0.50:/root/nfs_root /root/nfsmount # 写入一个测试文件 echo "hello nfs server" > /root/nfsmount/nginx/html/test.txt

NFS 服务器上执行以下命令,验证文件写入成功

cat /root/nfs_root/test.txt 

通过以下方式进行开机自动挂载

vi /etc/rc.local mount -t nfs 192.168.0.50:/root/nfs_root /root/nfsmount 

三、Nginx配置写入configmap

Nginx配置文件default.conf

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        listen 443 ssl;

        root /usr/share/nginx/html;
        index index.html;

        server_name localhost;
        ssl_certificate /etc/nginx/ssl/10900597_nginx.kcfurs.com_nginx/nginx.kcfurs.com.pem;
        ssl_certificate_key /etc/nginx/ssl/10900597_nginx.kcfurs.com_nginx/nginx.kcfurs.com.key;

        location / {
                try_files $uri $uri/ =404;
        }
}

注意事项:

  • 此处我的证书所在的Pod文件路径是/etc/nginx/ssl/_nginx.kcfurs.com_nginx/,需在创建Deployment时与secret进行挂载,详见下文5.1章节。
kubectl create configmap nginxconfigmap --from-file=default.conf 

在这里插入图片描述

四、阿里云证书写入secret

证书来自阿里云,此处就不进行过多介绍。

cd /root/apps/nginx/_nginx.kcfurs.com_nginx kubectl create secret tls nginx.kcfurs.com --key nginx.kcfurs.com.key --cert nginx.kcfurs.com.pem 

在这里插入图片描述

五、Deployment具体配置

5.1 完整配置文件

nginx-deployment.yaml

 --- kind: Deployment apiVersion: apps/v1 metadata: name: nginx namespace: default labels: app: nginx k8s.kuboard.cn/name: nginx annotations: { 
   } spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: creationTimestamp: null labels: app: nginx annotations: kubectl.kubernetes.io/restartedAt: '2023-08-17T16:50:05+08:00' spec: volumes: - name: config-data configMap: name: nginxconfigmap items: - key: default.conf path: default.conf defaultMode: 420 - name: html-data nfs: server: 192.168.0.50 path: /root/nfs_root/nginx/html
        - name: secret-data secret: secretName: nginx.kcfurs.com items: - key: tls.crt path: nginx.kcfurs.com.pem - key: tls.key path: nginx.kcfurs.com.key defaultMode: 420 containers: - name: nginx image: nginx ports: - name: http containerPort: 80 protocol: TCP - name: https containerPort: 443 protocol: TCP resources: { 
   } volumeMounts: - name: config-data mountPath: /etc/nginx/conf.d/ - name: html-data mountPath: /usr/share/nginx/html
            - name: secret-data mountPath: /etc/nginx/ssl/_nginx.kcfurs.com_nginx terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: IfNotPresent restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst securityContext: { 
   } schedulerName: default-scheduler strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 25% maxSurge: 25% revisionHistoryLimit: 10 progressDeadlineSeconds: 600 --- kind: Service apiVersion: v1 metadata: name: nginx namespace: default labels: app: nginx k8s.kuboard.cn/name: nginx spec: ports: - name: http protocol: TCP port: 80 targetPort: 80 nodePort: 31290 - name: https protocol: TCP port: 443 targetPort: 443 nodePort: 32623 selector: app: nginx type: NodePort sessionAffinity: ClientIP externalTrafficPolicy: Cluster sessionAffinityConfig: clientIP: timeoutSeconds: 10800 ipFamilies: - IPv4 ipFamilyPolicy: SingleStack internalTrafficPolicy: Cluster --- kind: Ingress apiVersion: networking.k8s.io/v1 metadata: name: nginx namespace: default labels: app: nginx k8s.kuboard.cn/name: nginx annotations: nginx.ingress.kubernetes.io/backend-protocol: HTTPS nginx.ingress.kubernetes.io/rewrite-target: / spec: ingressClassName: nginx-ingress tls: - hosts: - nginx.kcfurs.com secretName: nginx.kcfurs.com rules: - host: nginx.kcfurs.com http: paths: - path: / pathType: Prefix backend: service: name: nginx port: number: 443 --- kind: ConfigMap apiVersion: v1 metadata: name: nginxconfigmap namespace: default data: default.conf: "server {\r\n listen 80 default_server;\r\n listen [::]:80 default_server ipv6only=on;\r\n\r\n listen 443 ssl;\r\n\r\n root /usr/share/nginx/html;\r\n index index.html;\r\n\r\n server_name localhost;\r\n ssl_certificate /etc/nginx/ssl/10900597_nginx.kcfurs.com_nginx/nginx.kcfurs.com.pem;\r\n ssl_certificate_key /etc/nginx/ssl/10900597_nginx.kcfurs.com_nginx/nginx.kcfurs.com.key;\r\n\r\n location / {\r\n try_files $uri $uri/ =404;\r\n }\r\n}" --- kind: Secret apiVersion: v1 metadata: name: nginx.kcfurs.com namespace: default data: tls.crt: >- LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUY5akNDQk42Z0F3SUJBZ0lRQ2VCY004N3E1VVNWY056RFFOTG1oekFOQmdrcWhraUc5dzBCQVFzRkFEQnUKTVFzd0NRWURWUVFHRXdKVlV6RVZNQk1HQTFVRUNoTU1SR2xuYVVObGNuUWdTVzVqTVJrd0Z3WURWUVFMRXhCMwpkM2N1WkdsbmFXTmxjblF1WTI5dE1TMHdLd1lEVlFRREV5UkZibU55ZVhCMGFXOXVJRVYyWlhKNWQyaGxjbVVnClJGWWdWRXhUSUVOQklDMGdSekl3SGhjTk1qTXdPREUzTURBd01EQXdXaGNOTWpRd09ERTJNak0xT1RVNVdqQWIKTVJrd0Z3WURWUVFERXhCdVoybHVlQzVyWTJaMWNuTXVZMjl0TUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQwpBUThBTUlJQkNnS0NBUUVBd3paT1J4eGdMUFVrOS9NYnpFdXI3anBjc0pFUlJEMU0yeVo4SEtVV25oWVFwbHNDCi9XankzdEhaelExTnpOeHNiMnJ0WWh6UldlbHVEUmZidnliQjFMV3hXlIM1hyLzQ4ZEJHdkM4bGYwV25sTkQKVnZHc0VSelNnb2lmRTlKeEZ5NFJUbUltOVdDT0hSdTFKVVFreEp1QTZGSENHVTBlL1orZGp3aXdXSXlSdEpOVwo2NTRZVVBUaVFSa3NvQTlvMVlScVdVd1pFVTFUV2V3YjJELzN3TVJMUkEzZjE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m80WGlPT2VhcG9TenEKbEQ0cVNMQXplV2ZrcjFMOW8wS3hDQnhMSFlydWtQK0I2bkF4T1VsUER2NVNsd0ZZSVZPLzVPZ2VpMmRGV3RnMwptQ1ZBU0tzaDVmTkNPWXNEZGV2MmYwRUJsaGtCeE42ankxemFMWTVUSFN0bFJwWUZ2emtLCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg== type: kubernetes.io/tls 

注意事项:

  • 本示例Ingress使用到ingressClassName: nginx-ingress,基于Kuboard 提供的一种快速安装 ingress-nginx 的方法。

5.2 知识点 Ingress SSL 终止

默认情况下,SSLingress controller中被终止,所以从controllerpod的所有流量都是没有TLS(解密的流量)。

如果想要全程SSL,你可以通过正在使用的ingress controller添加支持的annotation。例如,在本章(应用已配置好SSL)示例Nginx ingress controller里面,为了让SSL流量到达应用,你可以使用nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"annotation

重要知识:

  • 更多关于Ingress-Nginx Controller配置示例,请见:https://kubernetes.github.io/ingress-nginx/examples/rewrite/

六、效果

6.1 通过ingress访问

  • 本示例K8S集群安装在内网环境,通过部署在外网的nps服务和内网的npc服务穿透至内网集群的nginx-ingress端口。
  • 外网的nps服务外网端口9091,对应 ingress-nginx-controller容器443的外部访问端口31700
  • 注意外网部署nps服务的 安全策略 ,保证网络可达。

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

6.2 通过服务的nodePort访问

  • 本示例K8S集群安装在内网环境,通过部署在外网的nps服务和内网的npc服务穿透至内网集群的nodePort端口。
  • 外网的nps服务外网端口8090,对应 nginx服务443的外部访问端口32623

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

今天的文章 K8S应用笔记 —— 部署Nginx服务发布前端项目(PV、PVC、Deployment、Service、Ingress )分享到此就结束了,感谢您的阅读。
编程小号
上一篇 2024-12-26 09:51
下一篇 2024-12-26 09:46

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/96878.html