隔离
资源对象的隔离
资源配额的隔离
CPU、Memory
限制 Pod 的 CPU、Memory 资源,超额无法被调度
Service
同一 namespace 下的 pod 可以通过 service name(dns)访问其它 pod,它们在名字上是隔离的
[root@m1 std]# k exec -it istio-ingressgateway-xxx sh -n istio-system# cat /etc/resolv.confnameserver 10.1.0.10search istio-system.svc.cluster.local svc.cluster.local cluster.local localdomainoptions ndots:5
注意:同一 namespace 下的 pod 访问其它 pod,在名字上是隔离的;但是在 ip 上不是隔离的,不同 namespace 下,可以通过 service ip、pod ip 互相访问 (service ip、pod ip 跟 namespace 无关)
[root@m1 std]# k get svc -n default
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
k8s-web-demo ClusterIP 10.1.169.212 <none> 80/TCP 14h
[root@m1 std]# k exec -it istio-ingressgateway-xxx sh -n istio-system
# ping 10.1.169.212
PING 10.1.169.212 (10.1.169.212) 56(84) bytes of data.
# 不同 namespace 的 pod 可以通过 ip 互相访问(service ip)
# curl 10.1.169.212
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.51 - Error report</title><style type="text/css">...
# 不同 namespace 的 pod 可以通过 ip 互相访问(pod ip)
# curl 10.244.0.36:8080
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.51 - Error report</title><style type="text/css">...
配置指定 namespace context
# 设置 context
kubectl config set-context ctx-dev \
--cluster=kubernetes \
--user=admin \
--namespace=dev \
--kubeconfig=/root/.kube/config
# 使用 context
kubectl config use-context ctx-dev --kubeconfig=/root/.kube/config
划分 namespace
- 按环境划分:dev、test
- 按团队划分
- 自定义多级划分(使用 “-“ 分割):NDX-全局管理(部门-团队)
- 注意:kubernetes namespace 不支持 “/“
