# 看一下新建结果 # kubectl get pvc -l app=nginx NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE www-web-0 Bound pvc-84f2721a-2a20-4a31-9bae-8339352488d0 1Gi RWO local-path 22m www-web-1 Bound pvc-f0a00b36-f728-40b9-b5f6-209db2e10fce 1Gi RWO local-path 6m44s
# pv也跟着创建出来了 # kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-84f2721a-2a20-4a31-9bae-8339352488d0 1Gi RWO Delete Bound default/www-web-0 local-path 6m16s pvc-f0a00b36-f728-40b9-b5f6-209db2e10fce 1Gi RWO Delete Bound default/www-web-1 local-path 6m13s
# 检测一下 # for i in 0 1; do kubectl exec web-$i -- sh -c 'echo hello $(hostname) > /usr/share/nginx/html/index.html'; done # for i in 0 1; do kubectl exec -it web-$i -- apt update -y ;done # for i in 0 1; do kubectl exec -it web-$i -- apt install curl -y; done # for i in 0 1; do kubectl exec -it web-$i -- curl http://localhost; done hello web-0 hello web-1
删除测试自重建
1 2 3 4 5 6 7 8 9
# kubectl delete pod -l app=nginx --force warning: Immediate deletion does not waitfor confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely. pod "web-0" force deleted pod "web-1" force deleted # for i in 0 1; do kubectl exec -it web-$i -- apt update -y ;done # for i in 0 1; do kubectl exec -it web-$i -- apt install curl -y; done # for i in 0 1; do kubectl exec -it web-$i -- curl http://localhost; done hello web-0 hello web-1
0x03 StatefulSet总结
StatefulSet只管Pod,和deployment的编号形式不同,会更短小精简一些。
1 2 3 4 5 6
$ for i in `kubectl get pod -l app=nginx |awk '{print $1}' |grep -v NAME`; do kubectl exec -it $i -- hostname; done web-0 web-1 nginx-deployment-848bcb569b-wscf6 nginx-deployment-848bcb569b-75fb9 nginx-deployment-848bcb569b-s8wq9