MrFuWen 2020-01-12
工作机制
在前面已经安装完成一个kubernetes的集群
[ ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION 192.168.132.131 Ready master 105m v1.17.0 192.168.132.132 Ready <none> 92m v1.17.0 192.168.132.133 Ready <none> 90m v1.17.0
[ ~]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE coredns-6955765f44-8kxdg 1/1 Running 0 108m coredns-6955765f44-m66bw 1/1 Running 0 108m etcd-192.168.132.131 1/1 Running 0 108m kube-apiserver-192.168.132.131 1/1 Running 0 108m kube-controller-manager-192.168.132.131 1/1 Running 0 108m kube-flannel-ds-amd64-dbckr 1/1 Running 0 95m kube-flannel-ds-amd64-fg972 1/1 Running 0 93m kube-flannel-ds-amd64-m9lgq 1/1 Running 0 104m kube-proxy-7xgt9 1/1 Running 0 95m kube-proxy-k8kb7 1/1 Running 0 93m kube-proxy-q867d 1/1 Running 0 108m kube-scheduler-192.168.132.131 1/1 Running 0 108m
kubectl 主要管理集群中的资源对象,容器也是资源
Node Namespace Container Pod Label Annotations ReplicaController ReplicaSet Deployment HPA Service Job
资源对象:分为集群级别资源(node,pv,clusterrole)和命名空间级别资源(pods)
node:节点,node不属于任何命名空间,是集群资源
集群安装的时候会自动帮助我们创建几个namesapce,查看namespace
[ ~]# kubectl get ns
NAME STATUS AGE default Active 137m kube-node-lease Active 137m kube-public Active 137m kube-system Active 137m kubernetes-dashboard Active 82m
kubectl get pods -n kube-system 这个操作就是查看kube-system 这个命名空间所有的容器
当我们执行kubectl get pods,不指定命名空间的话 ,就去查询default这个默认的命名空间,但是没任何容器运行
[ ~]# kubectl get pods
No resources found in default namespace.
[ ~]# kubectl create ns projecta
也可以通过提交资源描述文件进行创建
[ ~]# kubectl get ns
NAME STATUS AGE default Active 171m kube-node-lease Active 171m kube-public Active 171m kube-system Active 171m kubernetes-dashboard Active 116m projecta Active 6s
[ ~]# kubectl delete ns projecta
[ ~]# kubectl get ns
NAME STATUS AGE default Active 173m kube-node-lease Active 173m kube-public Active 173m kube-system Active 173m kubernetes-dashboard Active 117m
命名空间的命名规范
[ ~]# kubectl create ns Projecta
The Namespace "Projecta" is invalid: metadata.name: Invalid value: "Projecta": a DNS-1123 label must consist of lower case alphanumeric characters or ‘-‘, and must start and end with an alphanumeric character (e.g. ‘my-name‘, or ‘123-abc‘, regex used for validation is ‘[a-z0-9]([-a-z0-9]*[a-z0-9])?‘)
从这里就可以看到规则
[ ~]# mkdir -p /yamls/namespace
[ ~]# cd /yamls/namespace
[ namespace]# vim projectb.yaml
apiVersion: v1 #API版本 kind: Namespace #资源类型 metadata: name: projectb #命名空间名称
[ namespace]# kubectl apply -f projectb.yaml
[ namespace]# kubectl get ns
NAME STATUS AGE default Active 3h18m kube-node-lease Active 3h18m kube-public Active 3h18m kube-system Active 3h18m kubernetes-dashboard Active 142m projectb Active 19s
删除命名空间
[ namespace]# kubectl delete -f projectb.yaml
[ namespace]# kubectl get ns
NAME STATUS AGE default Active 3h18m kube-node-lease Active 3h18m kube-public Active 3h18m kube-system Active 3h18m kubernetes-dashboard Active 142m
命名空间简单介绍到这里
博主声明:本文的内容来源主要来自誉天教育晏威老师,由本人实验完成操作验证,需要的博友请联系誉天教育(http://www.yutianedu.com/),获得官方同意或者晏老师(https://www.cnblogs.com/breezey/)本人同意即可转载,谢谢!