Role
可以定義在一個namespace
中,只能用于授予對單個命名空間中的資源訪問的權限比如我們新建一個對默認命名空間中。默認的名稱空間:Default
成都創新互聯專業為企業提供青島網站建設、青島做網站、青島網站設計、青島網站制作等企業網站建設、網頁設計與制作、青島企業網站模板建站服務,十年青島做網站經驗,不只是建網站,更提供有價值的思路和整體網絡服務。
//查看名稱空間
[root@master ~]# kubectl get ns
//查看名稱空間詳細信息
[root@master ~]# kubectl describe ns default
//創建名稱空間
[root@master ~]# kubectl create ns bdqn
[root@master ~]# kubectl explain ns
[root@master ~]# vim 111-test.yaml
apiVersion: v1
kind: Namespace
metadata:
name: test
[root@master ~]# kubectl apply -f 111-test.yaml
[root@master ~]# kubectl get ns
刪除資源的兩種方法:
[root@master ~]# kubectl delete ns test
[root@master ~]# kubectl delete -f 111-test.yaml
Ps: namespace資源對象僅用于資源對象的隔離,并不能隔絕不同名稱空間的Pod之間的的通信,那是網絡策略資源的功能。
查看指定名稱空間的資源可以使用--namespace或者-n選項
[root@master ~]# kubectl get pod --namespace=bdqn
No resources found.
簡寫:
[root@master ~]# kubectl get pod -n bdqn
No resources found.
查看本集群運行的Pod
[root@master ~]# kubectl get pod -n kube-system
[root@master ~]# vim pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
spec:
containers:
- name: test-app
image: httpd
[root@master ~]# kubectl apply -f pod.yaml
pod/test-pod created
[root@master ~]# kubectl get pod
[root@master ~]# vim pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
namespace: bdqn //添加一行
spec:
containers:
- name: test-app
image: httpd
重新生成:
[root@master ~]# kubectl apply -f pod.yaml
pod/test-pod created
查看bdqn名稱空間
[root@master ~]# kubectl get pod -n bdqn
NAME READY STATUS RESTARTS AGE
test-pod 1/1 Running 0 80s
Pod中鏡像獲取策略:
PS:對于標簽“latest”或者是不存在,其默認策略下載及策略為“Always”,而對于其他標簽的鏡像,默認策略為“IfNotPresent”。
[root@master ~]# vim pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
namespace: bdqn
spec:
containers:
- name: test-app
image: httpd
imagePullPolicy: IfNotPresent
ports:
- protocol: TCP
containerPort: 80
[root@master ~]# kubectl delete pod -n bdqn test-pod
pod "test-pod" deleted
[root@master ~]# kubectl apply -f pod.yaml
pod/test-pod created
[root@master ~]# kubectl apply -f pod.yaml
pod/test-pod created
[root@master ~]# kubectl get pod -n bdqn
NAME READY STATUS RESTARTS AGE
test-pod 1/1 Running 0 26s
[root@master ~]# vim pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
namespace: bdqn
labels:
app: test-web
spec:
containers:
- name: test-app
image: httpd
imagePullPolicy: IfNotPresent
ports:
- protocol: TCP
containerPort: 90
[root@master ~]# vim svc.yaml
apiVersion: v1
kind: Service
metadata:
name: test-svc
namespace: bdqn
spec:
selector:
app: test-web
ports:
- port: 80
targetPort: 90
[root@master ~]# kubectl describe svc -n bdqn test-svc
[root@master ~]# vim healcheck.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
test: healcheck
name: healcheck
spec:
restartPolicy: OnFailure
containers:
- name: healthcheck
image: busybox
args:
- /bin/sh
- -c
- sleep 20; exit 1
[root@master ~]# kubectl apply -f healcheck.yaml
[root@master ~]# kubectl get pod -w
[root@master ~]# kubectl get pod -n kube-system
本文標題:Pod資源對象
URL分享:http://m.newbst.com/article8/pjdjip.html
成都網站建設公司_創新互聯,為您提供Google、小程序開發、軟件開發、網站排名、關鍵詞優化、網站策劃
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯