k8s - 集群文件共享

删除原tomcat-deploy

kubectl delete deployment tomcat-deploy

修改tomcat-deployment部署文件,增加mount属性

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: tomcat-deploy
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: tomcat-cluster
    spec:
      volumes:
      - name: web-app
        hostPath:
          path: /mnt     # 本地/mnt路径已经和之前的192.168.121.150:/usr/local/data/www-data通过nfs映射
      containers:
      - name: tomcat-cluster
        image: tomcat:latest
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: web-app  # 名字和上面volumes的name对应
          mountPath: /usr/local/tomcat/webapps  # 这样容器就知道tomcat的webapps路径实际指向了宿主机的/mnt

再部署以后,可以进入node1的tomcat容器检查

[bigcat@node1 ~]$ sudo docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED              STATUS              PORTS   NAMES
c3d82f7e5b64        tomcat                 "catalina.sh run"        About a minute ago   Up About a minute           k8s_tomcat-cluster_tomcat-deploy-6678xxx

sudo docker exec -it c3d82f7e5b64 /bin/bash
ls /usr/local/tomcat/webapps/

也可以在master上检查

[bigcat@master k8s]$ kubectl get pod -o wide
NAME                             READY   STATUS    RESTARTS   AGE   IP           NODE    NOMINATED NODE   READINESS GATES
tomcat-deploy-6678dccdc9-8pzqn   1/1     Running   0          37s   10.244.2.6   node2   <none>           <none>
tomcat-deploy-6678dccdc9-r57gc   1/1     Running   0          37s   10.244.1.8   node1   <none>           <none>

kubectl exec -it tomcat-deploy-6678dccdc9-8pzqn /bin/bash
上一篇:scss 注册vw和vh


下一篇:TS+Node 构建前端一键部署工具