最近去參加了CKA考試艾少,在速度上吃虧,以往喜歡復(fù)制粘貼修改摸板翼悴,在時(shí)間緊張的情況下這種方式的效率問題暴露了缚够,導(dǎo)致考試時(shí)間緊張,沒用時(shí)間解決難題鹦赎,考試會(huì)要求創(chuàng)建各種類型的資源谍椅,所以這準(zhǔn)備練習(xí)命令創(chuàng)建資源,提高操作效率:
如果能從命令行直接創(chuàng)建符合目的的資源就直接使用古话,如果命令參數(shù)不滿足需求雏吭,可以通過--dry-run -o yaml 參數(shù)輸出摸板不實(shí)際創(chuàng)建資源,下面是各種資源的創(chuàng)建示列陪踩,多數(shù)可以合并使用:
- 創(chuàng)建pod
加--restart=Never參數(shù)創(chuàng)建出來的資源就是pod
kubectl run busybox --image=busybox --dry-run -o yaml --restart=Never
- 創(chuàng)建cronjob
加--schedule=<cron>參數(shù)創(chuàng)建出來的資源就是cronjob
kubectl run busybox --image=busybox --dry-run -o yaml --schedule="* * * * *"
- 創(chuàng)建job
加--restart=OnFailure參數(shù)創(chuàng)建出來的資源就是jod
kubectl run busybox --image=busybox --dry-run -o yaml --restart=OnFailure
- 創(chuàng)建deployment
加--restart=Aalways參數(shù)創(chuàng)建出來的資源就是pod,這是默認(rèn)參數(shù)可以不指明
kubectl run busybox --image=busybox --dry-run -o yaml --restart=Aalways
- 創(chuàng)建使用ENV:
使用 --env, 多個(gè)環(huán)境變量重復(fù)參數(shù)指定
kubectl run nginx --image=nginx --dry-run -o yaml --env="dir=/mnt" --env="port=80"
- 創(chuàng)建資源限制及請(qǐng)求
kubectl run nginx --image=nginx --dry-run -o yaml --limits="cpu=100m,memory=256m" --requests="cpu=100m,memory=100M"
- 創(chuàng)建指定label
留意對(duì)象資源和列表資源在命令行參數(shù)中的表示規(guī)律杖们,重復(fù)使用參數(shù),用逗號(hào)分隔
kubectl run nginx --image=nginx --dry-run -o yaml --labels="app=nginx,owner=wangyijie,form=cmft"
- 指定多個(gè)啟動(dòng)參數(shù)
在最后以 -- 開頭可以以空格分隔指定多個(gè)命令參數(shù)
kubectl run nginx --image=nginx --dry-run -o yaml --schedule="* * * * *" --restart=OnFailure --labels="job=who" -- bash echo 123
9.創(chuàng)建服務(wù)
使用--expose參數(shù)會(huì)創(chuàng)建一個(gè)同名的服務(wù), 更多服務(wù)選項(xiàng)可以是kubectl expose deployment
kubectl run nginx --image=ngin --expose --port=80
-
遺憾是沒用創(chuàng)建DeamonSet和StatefulSet的參數(shù)肩狂,建議用快速github搜索摸板或者在系統(tǒng)中獲取摘完,kube-system下有daemonset的部署
search from githu
還有更關(guān)鍵的是在pod摸板中默寫各種資源的屬性配置