Role
可以定義在一個(gè)namespace
中,只能用于授予對(duì)單個(gè)命名空間中的資源訪問的權(quán)限比如我們新建一個(gè)對(duì)默認(rèn)命名空間中。默認(rèn)的名稱空間:Default
成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供青島網(wǎng)站建設(shè)、青島做網(wǎng)站、青島網(wǎng)站設(shè)計(jì)、青島網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、青島企業(yè)網(wǎng)站模板建站服務(wù),十年青島做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
//查看名稱空間
[root@master ~]# kubectl get ns
//查看名稱空間詳細(xì)信息
[root@master ~]# kubectl describe ns default
//創(chuàng)建名稱空間
[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資源對(duì)象僅用于資源對(duì)象的隔離,并不能隔絕不同名稱空間的Pod之間的的通信,那是網(wǎng)絡(luò)策略資源的功能。
查看指定名稱空間的資源可以使用--namespace或者-n選項(xiàng)
[root@master ~]# kubectl get pod --namespace=bdqn
No resources found.
簡(jiǎn)寫:
[root@master ~]# kubectl get pod -n bdqn
No resources found.
查看本集群運(yùn)行的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:對(duì)于標(biāo)簽“l(fā)atest”或者是不存在,其默認(rèn)策略下載及策略為“Always”,而對(duì)于其他標(biāo)簽的鏡像,默認(rèn)策略為“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