Kubernetes——使用NFS映射的目录

一、 使用NFS映射的目录

image-20211122183806514

1.1 删除原有的deploy

[root@k8s-master tomcat-deploy]# kubectl get deploy
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
tomcat-deploy   2/2     2            2           132m
[root@k8s-master tomcat-deploy]# kubectl delete deploy tomcat-deploy
deployment.extensions "tomcat-deploy" deleted
[root@k8s-master tomcat-deploy]# kubectl get deploy
No resources found.

1.2 删除原有的service

[root@k8s-master tomcat-deploy]# kubectl get service
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes       ClusterIP   10.96.0.1      <none>        443/TCP          16d
tomcat-service   NodePort    10.108.52.85   <none>        8000:31000/TCP   146m
[root@k8s-master tomcat-deploy]# kubectl delete service tomcat-service
service "tomcat-service" deleted

1.3 重新构建部署

1.3.1 切换至deploy部署脚本的目录

这一步是基于已经使用yml部署过tomcat集群的情况,如果没有部署过,可重新写一份yml进行提交

image-20211122175118647
1.3.2 修改deploy.yml

把test-deploy.yml修改为:

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
      containers:
      - name: tomcat-cluster
        image: tomcat:latest
        ports:
        - containerPort: 8080
        volumeMounts:
        # 此处的name需要和spec.template.spec.volumes.name一致
        - name: web-app
        # 挂载到pod内部容器的路径
          mountPath: /usr/local/tomcat/webapps
1.3.3 重新创建部署
[root@k8s-master tomcat-deploy]# kubectl create -f test-deploy.yml 
deployment.extensions/tomcat-deploy created
[root@k8s-master tomcat-deploy]# kubectl get deploy
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
tomcat-deploy   2/2     2            2           36m
[root@k8s-master tomcat-deploy]# kubectl get pod
NAME                             READY   STATUS    RESTARTS   AGE
tomcat-deploy-6678dccdc9-289cv   1/1     Running   0          36m
tomcat-deploy-6678dccdc9-z7wft   1/1     Running   0          36m
1.3.4 验证路径已经被容器内部映射进去

使用命令kubectl exec -ti [podName] bash

[root@k8s-master tomcat-deploy]# kubectl get pod
NAME                             READY   STATUS    RESTARTS   AGE
tomcat-deploy-6678dccdc9-289cv   1/1     Running   0          36m
tomcat-deploy-6678dccdc9-z7wft   1/1     Running   0          36m
[root@k8s-master tomcat-deploy]# kubectl exec -ti tomcat-deploy-6678dccdc9-289cv  bash
root@tomcat-deploy-6678dccdc9-289cv:/usr/local/tomcat# ls
BUILDING.txt  CONTRIBUTING.md  LICENSE	NOTICE	README.md  RELEASE-NOTES  RUNNING.txt  bin  conf  lib  logs  native-jni-lib  temp  webapps  webapps.dist  work
root@tomcat-deploy-6678dccdc9-289cv:/usr/local/tomcat# cd webapps
root@tomcat-deploy-6678dccdc9-289cv:/usr/local/tomcat/webapps# ls
a  b.txt  test.txt

Kubernetes其他文档列表

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐