博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
k8s 部署tomcat完整版
阅读量:7221 次
发布时间:2019-06-29

本文共 5464 字,大约阅读时间需要 18 分钟。

hot3.png

tomcat部署要点总结: 

利用configmap实现对server.xml的挂载利用tomcat-ingress实现对tomcat对外网络暴露 利用pv实现对tomcat日志存储利用statefulset创建tomcat pod。 利用mt-math.yaml创建mt-math命名空间注:默认已安装ingress-nginx,core-dns,NFS

1.NFS共享目录下创建tomcat 日志存放目录及项目存放目录;这里手动创建pv,当然pv也可以进行动态创建

mkdir -p /NFS/tomcat-wwwroot/ROOT/;mkdir -p /NFS/pv-tomcat-log/{01,02,03}  #创建日志目录及项目目录echo "k8s-ingress-tomcat-nfs-pv -Wyltest">/mnt/tomcat-wwwroot/ROOT/index.jsp #创建测试首页文件jspmkdir -p /server/yaml/app/tomcat #在master上创建yaml文件存放目录

2.创建3个pv yaml文件 分别为目录分别绑定到目录:/NFS/pv-tomcat-log/{01,02,03}

cd /server/yaml/app/tomcat/ cat tomcat-pv-nfs.yaml apiVersion: v1kind: PersistentVolumemetadata:  name: pv-nfs-tomcat01                     #创建的pv名称可创建多个.  namespace: mt-math                    #属于的命名空间spec:  capacity:    storage: 200M                        #创建的pv容量为1G  accessModes:  - ReadWriteMany                       #pv的访问模式:可读可写可挂在多个节点  persistentVolumeReclaimPolicy: Recycle #回收策略  #storageClassName: xxx  nfs:                                  #创建的pv数据来源    path: /NFS/pv-tomcat-log/01                     #数据源目录    server: 192.168.0.14                #数据源ip---apiVersion: v1kind: PersistentVolumemetadata:  name: pv-nfs-tomcat02                     #创建的pv名称可创建多个.  namespace: mt-math                    #属于的命名空间spec:  capacity:    storage: 200M                        #创建的pv容量为1G  accessModes:  - ReadWriteMany                       #pv的访问模式:可读可写可挂在多个节点  #persistentVolumeReclaimPolicy: Retain #回收策略  persistentVolumeReclaimPolicy: Recycle #回收策略 由于是持久化日志没必要删除pod保留日志。只是为了方便查看日志内容。  #storageClassName: xxx  nfs:                                  #创建的pv数据来源    path: /NFS/pv-tomcat-log/02                     #数据源目录    server: 192.168.0.14                #数据源ip---apiVersion: v1kind: PersistentVolumemetadata:  name: pv-nfs-tomcat03                     #创建的pv名称可创建多个.  namespace: mt-math                    #属于的命名空间spec:  capacity:    storage: 200M                        #创建的pv容量为1G  accessModes:  - ReadWriteMany                       #pv的访问模式:可读可写可挂在多个节点  persistentVolumeReclaimPolicy: Recycle #回收策略  #storageClassName: xxx  nfs:                                  #创建的pv数据来源    path: /NFS/pv-tomcat-log/03                     #数据源目录    server: 192.168.0.14                #数据源ip

3.创建mt-math命名空间,

cd /server/yaml/app/namespacecat mt-math.yaml apiVersion: v1kind: Namespacemetadata:  name: mt-math

4.创建对tomcat 配置文件server.xml创建configmap yaml文件

cat tomcat-configmap.yaml apiVersion: v1data:  server.xml: |    
   
   
   
     
     
     
     
     
     
     
     
     
     
     
     
       
       
     
     
     
       
       
       
       
       
       
       
       
       
       
       
       
       
         
         
         
         
           
           
         
         
           
           
           
           
         
       
     
   
kind: ConfigMapmetadata:  creationTimestamp: 2019-06-05T03:04:53Z  name: tomcat-configmap  namespace: mt-math

5.创建tomcat pod这里创建为无头服务

apiVersion: v1kind: Servicemetadata:  namespace: mt-math  name: tomcat  labels:    app: tomcatspec:  ports:  - port: 8080    name: web  clusterIP: None  selector:    app: tomcat---apiVersion: apps/v1kind: StatefulSetmetadata:  namespace: mt-math  name: webspec:  serviceName: "tomcat"  replicas: 3  selector:    matchLabels:      app: tomcat  template:    metadata:      namespace: mt-math      labels:        app: tomcat    spec:      containers:      - name: tomcat        image: harbor.bestyunyan.club:5588/library/tomcat7:01        ports:        - containerPort: 8080          name: web        volumeMounts:        - name: log-pvc          mountPath: /opt/tomcat/logs        - name: tomcat-nfs-webapps          mountPath: /opt/tomcat/webapps        - name: tomcat-serverxml          mountPath: /opt/tomcat/conf/server.xml          subPath: server.xml      volumes:                             - name: tomcat-nfs-webapps                     nfs:                                   server: 192.168.0.14                  path: /NFS/tomcat-wwwroot            - name: tomcat-serverxml        configMap:          name: tomcat-configmap          items:          - key: server.xml            path: server.xml      volumeClaimTemplates:  - metadata:      name: log-pvc      namespace: mt-math    spec:      accessModes: [ "ReadWriteMany" ]      resources:        requests:          storage: 200M

6.创建tomcat ingress 文件实现对外访问,这里写的域名为测试域名需要在客户端hosts添加进行本地解析

cat tomcat-ingress.yaml apiVersion: extensions/v1beta1kind: Ingressmetadata:  name: ingress-tomcat-wyl  namespace: mt-math  annotations:     kubernets.io/ingress.class: "nginx"    nginx.ingress.kubernetes.io/affinity: "cookie"    nginx.ingress.kubernetes.io/session-cookie-name: "route"    nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"spec:  rules:  - host: tomcat.bestyunyan.com  #生产中该域名应当可以被公网解析    http:      paths:      - path:         backend:          serviceName: tomcat          servicePort: 8080

7.查看创建的yamal文件

5a320c3cc9d2d5b671f161e10b93eb55c41.jpg

14b9fdffb506cd511e4aa48a8e98b276279.jpg

8.执行创建相关服务

ac15a15f7096c0a336b392799e60b6edf2d.jpg

9.检查服务状态OK

e676a7ac57ccd16d364df34406c19fdc8f5.jpg

1dacaec2dd9bdcf5c115f2be83fc4b3028e.jpg

10.测试dns解析是否OK

7d2a70a3806d689020de57c4a6efbf7d275.jpg

11.在客户端hosts中添加本地解析解析地址:

434b0a70722b026416be2391a80550b4556.jpg

42c42e2bec5944048737d0e62dfec0a23a3.jpg

12.客户端访问测试:

7d4f11ad5fbdeb654debbf9abf28cf9f63f.jpg

52a1d8641ae65fd9ed14dedc535f6cfd6ce.jpg

13.查看日志是否持久化, 为方便起见在master mnt目下挂载NFS进行查看

ce2d687f551ba1136d347f44ca57f8b8eec.jpg

14.查看pod中server.xml是不是我们挂载的。

5bf7a731e851bce3b4347916416688405fc.jpg

转载于:https://my.oschina.net/wangyunlong/blog/3058693

你可能感兴趣的文章
显示所有SAP图标的ABAP代码
查看>>
group by 与 order by 一起使用的时候
查看>>
HTML+CSS
查看>>
链接服务器创建
查看>>
用Vue的方式实现复选框
查看>>
mac下安装xampp、及其之上的组件安装
查看>>
C++内存对齐总结
查看>>
Web设计的速查卡(转)
查看>>
数据结构之哈夫曼树
查看>>
hdu1038
查看>>
CentOS 6.4下Zabbix的安装配置
查看>>
前端开发注意的问题 ,浏览器兼容性
查看>>
centos和redhat下 uwsgi配置
查看>>
Markdown 学习笔记
查看>>
vue-element-admin 多层路由问题
查看>>
Css问题 margin float 文档流 背景图底部充满
查看>>
JS match() 方法 使用
查看>>
关于shopee平台接口(php)对接示例
查看>>
BNU OJ 51000 BQG's Random String
查看>>
PAT (Advanced Level) 1044. Shopping in Mars (25)
查看>>