Role
能夠定義在一個namespace
中,只能用於授予對單個命名空間中的資源訪問的權限好比咱們新建一個對默認命名空間中。默認的名稱空間:Defaultweb
//查看名稱空間vim
[root@master ~]# kubectl get ns
//查看名稱空間詳細信息api
[root@master ~]# kubectl describe ns default
//建立名稱空間網絡
[root@master ~]# kubectl create ns bdqn
[root@master ~]# kubectl explain nsapp
[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之間的的通訊,那是網絡策略資源的功能。ide
查看指定名稱空間的資源可使用--namespace或者-n選項spa
[root@master ~]# kubectl get pod --namespace=bdqn No resources found.
簡寫:rest
[root@master ~]# kubectl get pod -n bdqn No resources found.
查看本集羣運行的Podcode
[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