diff --git a/content.zh/_index.md b/content.zh/_index.md index ec2bfab..143999f 100644 --- a/content.zh/_index.md +++ b/content.zh/_index.md @@ -54,114 +54,6 @@ OS: Rocky Linux 8.10 -## 五、设置基本的路由网络 - -绝大多数场景下,Kubernetes 网络是倚靠网络插件来完成的,典型的插件包括 `flannel`,`calico`,`weaver` 等等。 - -为了演示基本的 Pod 网络,我们在这里先不使用上面的经典插件,通过自己设置路由来完成;网络插件的安装会在后面的章节补充。 - -如下图,每个 Node 都会有一个独立的 Pod 网段。在 Master 和 Node 节点,我们会手动加上到 Pod 的路由。 - -![](/imgs/05-routes.png) - -### 添加 CNI 的配置 - -创建 CNI 的配置文件夹 - -```bash -mkdir /etc/cni/net.d/ -``` - -创建子网的配置 `/etc/cni/net.d/10-bridge.conf`。两个 node 上的配置稍有区别:node01 上分配了 `10.244.1.0/24`,我们写成下面的样子;如果是 node02 的,就把 `subnet` 参数的网段配置改为 `10.244.2.0/24`。 - -```json -{ - "cniVersion": "1.0.0", - "name": "bridge-network", - "type": "bridge", - "bridge": "cni0", - "isGateway": true, - "ipMasq": true, - "ipam": { - "type": "host-local", - "ranges": [ - [ - { - "subnet": "10.244.1.0/24" - } - ] - ], - "routes": [ - { - "dst": "0.0.0.0/0" - } - ] - } -} -``` - -创建回环配置 `/etc/cni/net.d/99-loopback.conf`,两个 node 上的配置一样。 - -```json -{ - "cniVersion": "1.1.0", - "name": "loopback", - "type": "loopback" -} -``` - -### 添加路由 - -最后,在三台机器上分别设置路由。 - -master 上: - -```bash -ip route add 10.244.1.0/24 via 192.168.56.11 -ip route add 10.244.2.0/24 via 192.168.56.12 -``` - -node01 上: - -```bash -ip route add 10.244.2.0/24 via 192.168.56.12 -``` - -node02 上: - -```bash -ip route add 10.244.1.0/24 via 192.168.56.11 -``` - -接下来我们就可以[运行 Pod](/cn/06-运行Pod.md)了。 - -## 六、运行 Pod - -### 运行 Pod - -在 master 机器上,执行下面的命令,创建一个 Deployment。 - -```bash -kubectl create deployment nginx --image=nginx:latest -``` - -执行下面的命令查看 Pod 状态。 - -```bash -kubectl get pods -o wide -``` - -当 Status 变成了 Running,这个 Pod 就启动成功了,同时还能看到 Pod 的 IP 地址。 - -从 master 节点上可以尝试 ping 和 wget 这个 IP。 - -```bash -ping -c 2 -wget -``` - -如果能 ping 通,wget 也能获取到 index.html 文件,说明网络正常。 - ## 七、安装 Flannel 网络插件和 kube-proxy 在前面的网络设置中我们使用系统间的路由表来做流量导向,这个方案可以在集群里访问 Pod 地址 diff --git a/content.zh/docs/advanced/_index.md b/content.zh/advanced/_index.md similarity index 100% rename from content.zh/docs/advanced/_index.md rename to content.zh/advanced/_index.md diff --git a/content.zh/docs/advanced/buttons.md b/content.zh/advanced/buttons.md similarity index 100% rename from content.zh/docs/advanced/buttons.md rename to content.zh/advanced/buttons.md diff --git a/content.zh/docs/advanced/columns.md b/content.zh/advanced/columns.md similarity index 100% rename from content.zh/docs/advanced/columns.md rename to content.zh/advanced/columns.md diff --git a/content.zh/docs/advanced/details.md b/content.zh/advanced/details.md similarity index 100% rename from content.zh/docs/advanced/details.md rename to content.zh/advanced/details.md diff --git a/content.zh/docs/advanced/hints.md b/content.zh/advanced/hints.md similarity index 100% rename from content.zh/docs/advanced/hints.md rename to content.zh/advanced/hints.md diff --git a/content.zh/docs/advanced/katex.md b/content.zh/advanced/katex.md similarity index 100% rename from content.zh/docs/advanced/katex.md rename to content.zh/advanced/katex.md diff --git a/content.zh/docs/advanced/mermaid.md b/content.zh/advanced/mermaid.md similarity index 100% rename from content.zh/docs/advanced/mermaid.md rename to content.zh/advanced/mermaid.md diff --git a/content.zh/docs/advanced/section/_index.md b/content.zh/advanced/section/_index.md similarity index 100% rename from content.zh/docs/advanced/section/_index.md rename to content.zh/advanced/section/_index.md diff --git a/content.zh/docs/advanced/section/first-page.md b/content.zh/advanced/section/first-page.md similarity index 100% rename from content.zh/docs/advanced/section/first-page.md rename to content.zh/advanced/section/first-page.md diff --git a/content.zh/docs/advanced/section/second-page.md b/content.zh/advanced/section/second-page.md similarity index 100% rename from content.zh/docs/advanced/section/second-page.md rename to content.zh/advanced/section/second-page.md diff --git a/content.zh/docs/advanced/tabs.md b/content.zh/advanced/tabs.md similarity index 100% rename from content.zh/docs/advanced/tabs.md rename to content.zh/advanced/tabs.md diff --git a/content.zh/docs/getting-started/_index.md b/content.zh/getting-started/_index.md similarity index 100% rename from content.zh/docs/getting-started/_index.md rename to content.zh/getting-started/_index.md diff --git a/content.zh/docs/getting-started/basic-info-and-server-preparation.md b/content.zh/getting-started/basic-info-and-server-preparation.md similarity index 100% rename from content.zh/docs/getting-started/basic-info-and-server-preparation.md rename to content.zh/getting-started/basic-info-and-server-preparation.md diff --git a/content.zh/docs/getting-started/certificates-and-keys.md b/content.zh/getting-started/certificates-and-keys.md similarity index 100% rename from content.zh/docs/getting-started/certificates-and-keys.md rename to content.zh/getting-started/certificates-and-keys.md diff --git a/content.zh/getting-started/config-network.md b/content.zh/getting-started/config-network.md new file mode 100644 index 0000000..2907ebb --- /dev/null +++ b/content.zh/getting-started/config-network.md @@ -0,0 +1,87 @@ +--- +title: 五、设置基本的路由网络 +weight: 15 +bookToc: false +--- + + +## 五、设置基本的路由网络 + +绝大多数场景下,Kubernetes 网络是倚靠网络插件来完成的,典型的插件包括 `flannel`,`calico`,`weaver` 等等。 + +为了演示基本的 Pod 网络,我们在这里先不使用上面的经典插件,通过自己设置路由来完成;网络插件的安装会在后面的章节补充。 + +如下图,每个 Node 都会有一个独立的 Pod 网段。在 Master 和 Node 节点,我们会手动加上到 Pod 的路由。 + +![](/imgs/05-routes.png) + +### 添加 CNI 的配置 + +创建 CNI 的配置文件夹 + +```bash +mkdir /etc/cni/net.d/ +``` + +创建子网的配置 `/etc/cni/net.d/10-bridge.conf`。两个 node 上的配置稍有区别:node01 上分配了 `10.244.1.0/24`,我们写成下面的样子;如果是 node02 的,就把 `subnet` 参数的网段配置改为 `10.244.2.0/24`。 + +```json +{ + "cniVersion": "1.0.0", + "name": "bridge-network", + "type": "bridge", + "bridge": "cni0", + "isGateway": true, + "ipMasq": true, + "ipam": { + "type": "host-local", + "ranges": [ + [ + { + "subnet": "10.244.1.0/24" + } + ] + ], + "routes": [ + { + "dst": "0.0.0.0/0" + } + ] + } +} +``` + +创建回环配置 `/etc/cni/net.d/99-loopback.conf`,两个 node 上的配置一样。 + +```json +{ + "cniVersion": "1.1.0", + "name": "loopback", + "type": "loopback" +} +``` + +### 添加路由 + +最后,在三台机器上分别设置路由。 + +master 上: + +```bash +ip route add 10.244.1.0/24 via 192.168.56.11 +ip route add 10.244.2.0/24 via 192.168.56.12 +``` + +node01 上: + +```bash +ip route add 10.244.2.0/24 via 192.168.56.12 +``` + +node02 上: + +```bash +ip route add 10.244.1.0/24 via 192.168.56.11 +``` + +接下来我们就可以[运行 Pod](/cn/06-运行Pod.md)了。 \ No newline at end of file diff --git a/content.zh/docs/getting-started/hidden.md b/content.zh/getting-started/hidden.md similarity index 100% rename from content.zh/docs/getting-started/hidden.md rename to content.zh/getting-started/hidden.md diff --git a/content.zh/docs/getting-started/master-node.md b/content.zh/getting-started/master-node.md similarity index 100% rename from content.zh/docs/getting-started/master-node.md rename to content.zh/getting-started/master-node.md diff --git a/content.zh/getting-started/run-pods.md b/content.zh/getting-started/run-pods.md new file mode 100644 index 0000000..945ef9c --- /dev/null +++ b/content.zh/getting-started/run-pods.md @@ -0,0 +1,33 @@ +--- +title: 六、运行 Pod +weight: 16 +bookToc: false +--- + + +## 六、运行 Pod + +### 运行 Pod + +在 master 机器上,执行下面的命令,创建一个 Deployment。 + +```bash +kubectl create deployment nginx --image=nginx:latest +``` + +执行下面的命令查看 Pod 状态。 + +```bash +kubectl get pods -o wide +``` + +当 Status 变成了 Running,这个 Pod 就启动成功了,同时还能看到 Pod 的 IP 地址。 + +从 master 节点上可以尝试 ping 和 wget 这个 IP。 + +```bash +ping -c 2 +wget +``` + +如果能 ping 通,wget 也能获取到 index.html 文件,说明网络正常。 \ No newline at end of file diff --git a/content.zh/docs/getting-started/worker-node.md b/content.zh/getting-started/worker-node.md similarity index 100% rename from content.zh/docs/getting-started/worker-node.md rename to content.zh/getting-started/worker-node.md diff --git a/hugo.toml b/hugo.toml index 2341135..4aabb62 100644 --- a/hugo.toml +++ b/hugo.toml @@ -23,3 +23,7 @@ theme = 'hugo-book' languageName = 'Chinese' contentDir = 'content.zh' weight = 2 + +[params] + +BookSection = '*' \ No newline at end of file