使用Deployment控制器创建Pods并使Service发布到外网可访问

由于NFS支持节点共同读取及写入,所以可使用Deployment控制器创建多个Pod,并且每一个Pod都共享同一个目录

 

k8s-master

kubnet@hadoop2 volumes]$ vim pod-deploy.yml
            
       apiVersion: v1 kind: Service metadata: name: myapp
-nfs-svc namespace: default labels: app: myapp release: stable spec: selector: app: myapp volume: nfs type: NodePort ports: - name: myapp-nfs-web port: 80 targetPort: 80 nodePort: 30002 --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: myapp-nfs namespace: default labels: app: myapp release: stable spec: replicas: 3 template: metadata: labels: app: myapp volume: nfs spec: containers: - name: myapp-nfs-pod image: fangwenkai/kubernetes:v1.16 imagePullPolicy: IfNotPresent volumeMounts: - name: web-nfs mountPath: /usr/share/nginx/html/ readOnly: false volumes: - name: web-nfs nfs: path: /k8s/volumes server: 192.168.23.103
kubnet@hadoop2 volumes]$ kubectl get svc
kubnet@hadoop2 volumes]$ kubectl get deployment
kubnet@hadoop2 volumes]$ kubectl get pods --show-labels -l app=myapp,volume=nfs

 网页端访问本机IP+Port即可访问到index.html主页中内容(index.html内容在上一节中定义的,值为NFS-Node的主机名)

 

posted @ 2019-07-11 15:42  k-free  阅读(426)  评论(0编辑  收藏  举报