k8s部署tomcat数据持久化
1、部署nfs服务器yum -y install nfs-utils rpcbind11.2、启动nfs服务systemctl start nfs11.3、检查rpcbindNFS:~ # rpcinfo -p localhostprogram vers protoport service1000004udp111 portmapper1000003udp111 portmapper100...
·
1、部署nfs服务器
yum -y install nfs-utils rpcbind
1.2、启动nfs服务
systemctl start nfs
1.3、检查rpcbind
NFS:~ # rpcinfo -p localhost
program vers proto port service
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100024 1 udp 40026 status
100024 1 tcp 53654 status
100005 1 udp 20048 mountd
100005 1 tcp 20048 mountd
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 38414 nlockmgr
100021 3 udp 38414 nlockmgr
100021 4 udp 38414 nlockmgr
100021 1 tcp 36471 nlockmgr
100021 3 tcp 36471 nlockmgr
100021 4 tcp 36471 nlockmgr
说明:出现以上说明正常
1.4、检查nfs服务
NFS:~ # showmount -e localhost
Export list for localhost:
/app/tomcat_jpress 192.168.1.0/24
/app/nginx_conf 192.168.1.0/24
/app/tomcat_carsharing 192.168.1.0/24
/app/mysql1_data 192.168.1.0/24
说明:出现以上信息说明正常
1.5、配置共享目录
cat /etc/exports
/app/tomcat_jpress 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
1.6、加载新添加的目录
exportfs -rv
2、node节点部署nfs及rpcbind
yum -y install nfs-utils rpcbind
说明:只安装不启动就行
3、部署tomcat持久化yaml文件
cat my_tomcat_chijiu.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat
spec:
replicas: 2
selector:
matchLabels:
app: tomcat
minReadySeconds: 1
progressDeadlineSeconds: 60
revisionHistoryLimit: 5
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
name: tomcat
labels:
app: tomcat
spec:
containers:
- name: tomcat
image: tomcat:8
ports:
- containerPort: 8080
volumeMounts:
- name: tz-config
mountPath: /etc/localtime #同步时间
- name: tomcat-webapp
mountPath: /usr/local/tomcat/webapps #容器中tomcat站点目录
readOnly: false #关闭目录的只读权限
volumes:
- name: tz-config
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai #本地的时间配置文件
- name: tomcat-webapp
nfs:
server: 192.168.1.89 #nfs服务器地址
path: /app/tomcat_jpress #nfs共享的目录
4、部署tomcat的service文件
cat tomcat_svc_test.yaml
apiVersion: v1
kind: Service
metadata:
name: tomcat
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30012
selector:
app: tomcat
5、创建pod及service
kubectl create -f my_tomcat_chijiu.yaml
kubectl create -f tomcat_svc.yaml
6、检查是否启动成功
[root@k8s_master k8s_yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
tomcat-7bc7ffdddb-bkhj8 1/1 Running 0 45m
tomcat-7bc7ffdddb-cjqzc 1/1 Running 0 28m
[root@k8s_master k8s_yaml]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 5d20h
tomcat NodePort 10.254.174.178 <none> 8080:30009/TCP 3d11h
7、进入查看
kubectl exec -it <podName> -c <containerName> -n <namespace> -- shell comand
kubectl exec -it tomcat-5cf68746d-vjdq5 -n finereport -- /bin/bash
更多推荐
已为社区贡献5条内容
所有评论(0)