Create a shared storage directory
yum install -y rpcbind nfs-utils
create a shared directory
mkdir -p / home / sharedir / www
modify directory permissions
chmod 0755 -R sharedir
modify the configuration file NFS
VI / etc / Exports
/ Home / SHAREDIR 192.168.2.0 (RW, the no_root_squash, no_all_squash , sync)
to start nfs: systemctl start nfs
pv create a document
vi httpd-pv.yaml
apiVersion: v1 kind: PersistentVolume metadata: name: httpd-pv spec: capacity: storage: 1Gi accessModes: - ReadWriteOnce nfs: path: /home/sharedir/www server: 192.168.2.120
pvc create a document
vi httpd-pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: httpd-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi
httpd create file
vi httpd.yaml
apiVersion: v1 kind: Service metadata: name: httpd spec: type: NodePort ports: - port: 80 nodePort: 32222 targetPort: 80 selector: app: httpd --- apiVersion: apps/v1 kind: Deployment metadata: name: httpd spec: selector: matchLabels: app: httpd template: metadata: labels: app: httpd spec: containers: - name: httpd image: httpd ports: - name: httpd containerPort: 80 volumeMounts: - name: httpd-persistent-storage mountPath: /usr/local/apache2/htdocs volumes: - name: httpd-persistent-storage persistentVolumeClaim: claimName: httpd-pvc
Perform resource creation
kubectl the Apply -f httpd-pv.yaml
kubectl the Apply -f httpd-pvc.yaml
kubectl the Apply -f httpd.yaml
查看容器
[root@master mysql]# kubectl get pod
NAME READY STATUS RESTARTS AGE
httpd-65c5d64bd7-pmwwr 1/1 Running 0 2m19s
View Service
[root @ Master MySQL] # kubectl GET svc
NAME the TYPE CLUSTER-the EXTERNAL IP-IP PORT (S) AGE
httpd NodePort 10.103.239.58 <none> 80: 32222 / TCP 22M
进入httpd容器
[root@master mysql]# kubectl exec -it httpd-65c5d64bd7-pmwwr bash
root@httpd-65c5d64bd7-pmwwr:/usr/local/apache2#
Visit site:
http://192.168.2.122:32222/
Modify the number of copies
kubectl scale deployment httpd --replicas=2