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