File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1085,13 +1085,64 @@ curl http://192.168.59.100/
10851085# (....Thank you for using nginx.....)
10861086```
10871087
1088- 上面的教程中将所有流量都发送到 Ingress 的架构如下图所示 :
1088+ 上面的教程中将所有流量都发送到 Ingress 中,如下图所示 :
10891089
10901090![ ingress] ( https://cdn.jsdelivr.net/gh/guangzhengli/PicURL@master/uPic/ingress.png )
10911091
1092+ ## Namespace
1093+
1094+ 在实际的开发当中,有时候我们需要不同的环境来做开发和测试,例如 ` dev ` 环境给开发使用,` test ` 环境给 QA 使用,那么 k8s 能不能在不同环境 ` dev ` ` test ` ` uat ` ` prod ` 中区分资源,让不同环境的资源独立不影响呢,答案是肯定的,k8s 提供了名为 Namespace 的资源来帮助隔离资源。
1095+
1096+ 在 Kubernetes 中,** 名字空间(Namespace)** 提供一种机制,将同一集群中的资源划分为相互隔离的组。 同一名字空间内的资源名称要唯一,但跨名字空间时没有这个要求。 名字空间作用域仅针对带有名字空间的对象,例如 Deployment、Service 等。
1097+
1098+ 前面的教程中,默认使用的 namespace 是 ` default ` 。
1099+
1100+ 下面展示如何创建一个新的 namespace, ` namespace.yaml ` 文件定义了两个不同的 namespace,分别是 ` dev ` 和 ` test ` 。
1101+
1102+ ``` yaml
1103+ apiVersion : v1
1104+ kind : Namespace
1105+ metadata :
1106+ name : dev
1107+
1108+ ---
1109+
1110+ apiVersion : v1
1111+ kind : Namespace
1112+ metadata :
1113+ name : test
1114+ ` ` `
1115+
1116+ 可以通过` kubectl apply -f namespaces.yaml` 创建两个新的 namespace,分别是 `dev` 和 `test`。
1117+
1118+ ` ` ` yaml
1119+ kubectl apply -f namespaces.yaml
1120+ # namespace/dev created
1121+ # namespace/test created
1122+
1123+
1124+ kubectl get namespaces
1125+ # NAME STATUS AGE
1126+ # default Active 215d
1127+ # dev Active 2m44s
1128+ # ingress-nginx Active 110d
1129+ # kube-node-lease Active 215d
1130+ # kube-public Active 215d
1131+ # kube-system Active 215d
1132+ # test Active 2m44s
1133+ ` ` `
1134+
1135+ 那么如何在新的 namespace 下创建资源和获取资源呢?只需要在命令后面加上 `-n namespace` 即可。例如根据上面教程中,在名为 `dev` 的 namespace 下创建 `hellok8s:v3` 的 deployment。
1136+
1137+ ` ` ` shell
1138+ kubectl apply -f deployment.yaml -n dev
1139+
1140+ kubectl get pods -n dev
1141+ ` ` `
1142+
10921143# # Configmap
10931144
1094- ### env var
1145+ 在实际的开发当中,有一些配置是不适合放到 docker image 或者代码中的,例如在不同环境 `dev` `test` `uat` `prod` 中,数据库的地址往往是不一样的,这时就需要有一种资源,能够定义配置信息,并在不同的
10951146
10961147` ` ` ruby
10971148require "sinatra"
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ apiVersion: v1
22kind : Namespace
33metadata :
44 name : dev
5+
6+ ---
57
6-
7- # kubectl get pods --all-namespaces
8- # kubectl get all --all-namespaces
8+ apiVersion : v1
9+ kind : Namespace
10+ metadata :
11+ name : test
You can’t perform that action at this time.
0 commit comments