20201222 kubernetes (四)
課堂資料
NFS
nfs 網路存儲、pod重啟後數據依在
第一步:
install nfs-server
設置掛載路徑
掛載路徑需要創建出來
第二步:在其他 node 也安裝 nfs
第三步:啟動nfs-server
第四步:在 k8s 集群部署應用使用 nfs 以持久網路儲存
課堂練習
NFS
安裝 NFS Server
yum install nfs-utils
設定分享目錄
mkdir -p /var/nfssharechmod -R 777 /var/nfsshare/
開啟 /etc/exports 檔案
vim /etc/exports
啟動 NFS Server, 設定開機自動執行及在 firewalld 開放 NFS
systemctl restart rpcbindsystemctl restart nfs-serversystemctl status rpcbind
systemctl status nfs-servercd /var/nfsshare/
lstouch 1 2 3ls
cdgedit pv.yaml pvc.yamlls /var/nfsshare/kubectl apply -f pv.yamlkubectl get pvcd /var/nfsshare/ls
echo "hi" > hi.htmcdlskubectl apply -f pvc.yamlkubectl get pods -o widekubectl get deploymentkubectl delete deployment httpd
kubectl get deploymentkubectl get pod -o widekubectl get deploymentkubectl describe deployment httpd-dep2
kubectl get pvckubectl get deploymentkubectl get deploymentkubectl get svckubectl delete svc httpdkubectl delete svc httpd2kubectl get svckubectl get pod
kubectl delete pod --allkubectl get podkubectl describe deployment httpd-dep2
kubectl get pod -o wide
lskubectl get pvckubectl get deploymentkubectl describe deployment httpd-dep2
kubectl get podgedit pvc.yamlpvc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-dep2
spec:
selector:
matchLabels:
app: httpd
replicas: 1
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: httpd:2.4.46
ports:
- containerPort: 80
# volumeMounts:
# - name: wwwroot
# mountPath: /usr/local/apache2/htdocs
# ports:
# - containerPort: 80
# volumes:
# - name: wwwroot
# persistentVolumeClaim:
# claimName: my-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gikubectl apply -f pvc.yamlkubectl get deployment
kubectl get podkubectl get pod -o widecurl [podID]gedit pvc.yamlpvc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-dep2
spec:
selector:
matchLabels:
app: httpd
replicas: 1
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: httpd:2.4.46
ports:
- containerPort: 80
# volumeMounts:
# - name: wwwroot
# mountPath: /usr/local/apache2/htdocs
# ports:
# - containerPort: 80
volumes:
- name: wwwroot
persistentVolumeClaim:
claimName: my-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
kubectl apply -f pvc.yamlkubectl get deploymentkubectl get pod -o widecurl [podID]
gedit pvc.yamlpvc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-dep2
spec:
selector:
matchLabels:
app: httpd
replicas: 1
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: httpd:2.4.46
ports:
- containerPort: 80
# volumeMounts:
# - name: wwwroot
# mountPath: /usr/local/apache2/htdocs
ports:
- containerPort: 80
volumes:
- name: wwwroot
persistentVolumeClaim:
claimName: my-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gikubectl apply -f pvc.yamlkubectl get deploymentkubectl get pod -o wide
curl [podID]kubectl get podkubectl exec [podName] -it -- bashcd htdocs/lspwdexitkubectl get svc
gedit pvc.yamlpvc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-dep2
spec:
selector:
matchLabels:
app: httpd
replicas: 1
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: httpd:2.4.46
ports:
- containerPort: 80
volumeMounts:
- name: wwwroot
mountPath: /usr/local/apache2/htdocs
ports:
- containerPort: 80
volumes:
- name: wwwroot
persistentVolumeClaim:
claimName: my-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gikubectl apply -f pvc.yamlkubectl get deployment
kubectl get podkubectl get pods
kubectl describe deployment httpd-dep2
cd ..lscdmkdir pvcd pvgedit 1.yaml 2.yaml 3.yaml &1.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
storageClassName: test
nfs:
path: /var/nfsshare
server: 192.168.8.1292.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
storageClassName: test 3.yaml
apiVersion: v1
kind: Pod
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: my-pvc
containers:
- name: task-pv-container
image: httpd:2.4.46
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/local/apache2/htdocs"
name: task-pv-storage
kubectl apply -f 1.yamlkubectl get pvkubectl apply -f 2.yamlkubectl get pvckubectl apply -f 3.yamlkubectl get podkubectl get pod -o wide
cd /var/nfsshare/lscurl [podID]/hi.htmecho "abc" > abc.htmcurl [podID]/abc.htmlskubectl get podkubectl delete pod task-pv-podkubectl get pod
cdcd pvkubectl apply -f 3.yamlkubectl get podkubectl get pod -o widecurl [podID]/hi.htmcurl [podID]/abc.htm
ConfigMap
cdmkdir /cmcd cmgedit myconfigmap.yaml
cd testcmgedit mysql.conf redis.confcat mysql.confcat redis.conf
cd ..kubectl create configmap cm-demo1 --from-file=testcmkubectl get cmkubectl describe cm cm-demo1kubectl create configmap cm-demo3 --from-literal=db.host=localhost --from-literal=db.port=3306kubectl get cm
kubectl describe cm cm-demo3gedit testpod.yaml
kubectl apply -f testpod.yamlkubectl get podkubectl delete pod --allgedit testpod.yaml
kubectl apply -f testpod.yamlkubectl get podkubectl logs testcm2-pod
Last updated
Was this helpful?


