名字是啥?
答:集群中每个对象的名称对于该类型的资源都是唯一的。并且每一个对象在整个集群中也有一个唯一的UID.
名称空间是啥?
答:名称空间将集群划分为多个领域
什么时候使用?
答: 企业中有多人使用时候,可以进行权限管控
怎么查看?
答:看输出 是false 还是 true
kubectl api-resources --namespace=false
kubectl api-resources --namespace=true
名称空间和dns的关系?
答:
创建服务时,它将创建相应的DNS条目,这个条目的形式是<service-name>.<namespace-name>.svc.cluster.local
上面的namespace-name 是啥就是啥
默认的名称空间?
答:
[root@k8s-01 ~]# kubectl get namespace
NAME STATUS AGE
default Active 2d10h
kube-flannel Active 2d10h
kube-node-lease Active 2d10h
kube-public Active 2d10h
kube-system Active 2d10h
[root@k8s-01 ~]# kubectl get ns
NAME STATUS AGE
default Active 2d10h
kube-flannel Active 2d10h
kube-node-lease Active 2d10h
kube-public Active 2d10h # 保留给集群使用,保持基本使用
kube-system Active 2d10h #管理相关的组件
kubectl get pod -n kube-system
kubectl describe -n kube-system
如何新增一个名称空间
答:如下命令
[root@k8s-01 ~]# kubectl create ns dev
namespace/dev created
[root@k8s-01 ~]# kubectl get ns
NAME STATUS AGE
default Active 2d10h
dev Active 6s
kube-flannel Active 2d10h
kube-node-lease Active 2d10h
kube-public Active 2d10h
kube-system Active 2d10h
[root@k8s-01 ~]# kubectl delete ns dev
如何利用json 创建名称空间
答:
[root@k8s-01 chapter06]# kubectl apply -f namespace-dev.json
namespace/development created
[root@k8s-01 chapter06]# kubectl app^C
[root@k8s-01 chapter06]# kubectl apply -f namespace-prod.json
namespace/production created
[root@k8s-01 chapter06]# kubectl get ns
NAME STATUS AGE
default Active 2d10h
development Active 17s
kube-flannel Active 2d10h
kube-node-lease Active 2d10h
kube-public Active 2d10h
kube-system Active 2d10h
production Active 4s
[root@k8s-01 chapter06]# kubectl get ns --show-labels
NAME STATUS AGE LABELS
default Active 2d10h <none>
development Active 35s name=development
kube-flannel Active 2d10h k8s-app=flannel,pod-security.kubernetes.io/enforce=privileged
kube-node-lease Active 2d10h <none>
kube-public Active 2d10h <none>
kube-system Active 2d10h <none>
production Active 22s name=production
[root@k8s-01 chapter06]# cat namespace-prod.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "production",
"labels": {
"name": "production"
}
}
}[root@k8s-01 chapter06]# cat namespace-dev.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "development",
"labels": {
"name": "development"
}
}
}