在完成前面kubernetes数据持久化的学习之后,本节我们开始尝试在k8s集群中部署nginx应用,对于nginx来说,需要持久化的数据主要有两块:
一、配置nginx网页文件持久化 # cat nginx-rc.yaml apiVersion: v1 kind: ReplicationController metadata: name: nginx-test labels: name: nginx-test spec: replicas: 2 selector: name: nginx-test template: metadata: labels: name: nginx-test spec: containers: - name: nginx-test image: docker.io/nginx volumeMounts: - mountPath: /usr/share/nginx/html name: nginx-data ports: - containerPort: 80 volumes: - name: nginx-data persistentVolumeClaim: claimName: nfs-data 2、sevice配置文件如下 # cat nginx-svc.yaml apiVersion: v1 kind: Service metadata: name: nginx-test labels: name: nginx-test spec: type: NodePort ports: - port: 80 protocol: TCP targetPort: 80 name: http nodePort: 30088 selector: name: nginx-test 3、通过配置文件创建ReplicationController和service # kubectl create -f nginx-rc.yaml # kubectl create -f nginx-svc.yaml
# echo 'Hello, Welcome to my website...' > /home/index.html
# cat nginx-rc.yaml apiVersion: v1 kind: ReplicationController metadata: name: nginx-test labels: name: nginx-test spec: replicas: 2 selector: name: nginx-test template: metadata: labels: name: nginx-test spec: containers: - name: nginx-test image: docker.io/nginx volumeMounts: - mountPath: /usr/share/nginx/html name: nginx-data - mountPath: /etc/nginx name: nginx-etc ports: - containerPort: 80 volumes: - name: nginx-data persistentVolumeClaim: claimName: nfs-data - name: nginx-etc persistentVolumeClaim: claimName: nfs-nginx-etc 3、重新创建rc验证两个PVC是否成功挂载 # kubectl delete -f nginx-rc.yaml # kubectl create -f nginx-rc.yaml # kubectl get pod # kubectl describe pod nginx-test-kllfw
(责任编辑:IT) |