Skip to content

Commit a07662e

Browse files
committed
feat: add vitepress to render webpage
1 parent e098da2 commit a07662e

17 files changed

Lines changed: 214 additions & 37 deletions

.vitepress/config.mts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { defineConfig } from 'vitepress'
2+
3+
// https://vitepress.dev/reference/site-config
4+
export default defineConfig({
5+
title: "Kubernetes 练习手册",
6+
description: "A tutorials for k8s",
7+
themeConfig: {
8+
// https://vitepress.dev/reference/default-theme-config
9+
nav: [
10+
{ text: 'Home', link: '/' },
11+
{ text: 'Examples', link: '/markdown-examples' }
12+
],
13+
14+
sidebar: [
15+
{
16+
text: '开始',
17+
items: [
18+
{ text: '准备工作', link: 'docs/pre' },
19+
]
20+
},
21+
{
22+
text: 'Kubernetes',
23+
items: [
24+
{ text: 'Container', link: 'docs/container' },
25+
{ text: 'Pod', link: 'docs/pod' },
26+
{ text: 'Deployment', link: 'docs/deployment' },
27+
{ text: 'Service', link: 'docs/service' },
28+
{ text: 'Ingress', link: 'docs/ingress' },
29+
{ text: 'Namespace', link: 'docs/namespace' },
30+
{ text: 'ConfigMap', link: 'docs/configmap' },
31+
{ text: 'Secret', link: 'docs/secret' },
32+
{ text: 'Job', link: 'docs/job' },
33+
]
34+
},
35+
{
36+
text: 'Helm',
37+
items: [
38+
{ text: 'Helm', link: 'docs/helm' },
39+
]
40+
},
41+
{
42+
text: 'Others',
43+
items: [
44+
{ text: 'Dashboard', link: 'docs/dashboard' },
45+
]
46+
}
47+
],
48+
49+
socialLinks: [
50+
{ icon: 'github', link: 'https://github.com/guangzhengli/k8s-tutorials' },
51+
{ icon: 'twitter', link: 'https://twitter.com/iguangzhengli' },
52+
{ icon: { svg: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-user"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>'},
53+
link: 'https://guangzhengli.com' },
54+
{ icon: { svg: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-coffee"><path d="M17 8h1a4 4 0 1 1 0 8h-1"/><path d="M3 8h14v9a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4Z"/><line x1="6" x2="6" y1="2" y2="4"/><line x1="10" x2="10" y1="2" y2="4"/><line x1="14" x2="14" y1="2" y2="4"/></svg>'},
55+
link: 'https://guangzhengli.com/sponsors' },
56+
]
57+
}
58+
})

.vitepress/theme/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://vitepress.dev/guide/custom-theme
2+
import { h } from 'vue'
3+
import Theme from 'vitepress/theme'
4+
import './style.css'
5+
6+
export default {
7+
extends: Theme,
8+
Layout: () => {
9+
return h(Theme.Layout, null, {
10+
// https://vitepress.dev/guide/extending-default-theme#layout-slots
11+
})
12+
},
13+
enhanceApp({ app, router, siteData }) {
14+
// ...
15+
}
16+
}

.vitepress/theme/style.css

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* Customize default theme styling by overriding CSS variables:
3+
* https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css
4+
*/
5+
6+
/**
7+
* Colors
8+
* -------------------------------------------------------------------------- */
9+
10+
:root {
11+
--vp-c-brand: #646cff;
12+
--vp-c-brand-light: #747bff;
13+
--vp-c-brand-lighter: #9499ff;
14+
--vp-c-brand-lightest: #bcc0ff;
15+
--vp-c-brand-dark: #535bf2;
16+
--vp-c-brand-darker: #454ce1;
17+
--vp-c-brand-dimm: rgba(100, 108, 255, 0.08);
18+
}
19+
20+
/**
21+
* Component: Button
22+
* -------------------------------------------------------------------------- */
23+
24+
:root {
25+
--vp-button-brand-border: var(--vp-c-brand-light);
26+
--vp-button-brand-text: var(--vp-c-white);
27+
--vp-button-brand-bg: var(--vp-c-brand);
28+
--vp-button-brand-hover-border: var(--vp-c-brand-light);
29+
--vp-button-brand-hover-text: var(--vp-c-white);
30+
--vp-button-brand-hover-bg: var(--vp-c-brand-light);
31+
--vp-button-brand-active-border: var(--vp-c-brand-light);
32+
--vp-button-brand-active-text: var(--vp-c-white);
33+
--vp-button-brand-active-bg: var(--vp-button-brand-bg);
34+
}
35+
36+
/**
37+
* Component: Home
38+
* -------------------------------------------------------------------------- */
39+
40+
:root {
41+
--vp-home-hero-name-color: transparent;
42+
--vp-home-hero-name-background: -webkit-linear-gradient(
43+
120deg,
44+
#bd34fe 30%,
45+
#41d1ff
46+
);
47+
48+
--vp-home-hero-image-background-image: linear-gradient(
49+
-45deg,
50+
#bd34fe 50%,
51+
#47caff 50%
52+
);
53+
--vp-home-hero-image-filter: blur(40px);
54+
}
55+
56+
@media (min-width: 640px) {
57+
:root {
58+
--vp-home-hero-image-filter: blur(56px);
59+
}
60+
}
61+
62+
@media (min-width: 960px) {
63+
:root {
64+
--vp-home-hero-image-filter: blur(72px);
65+
}
66+
}
67+
68+
/**
69+
* Component: Custom Block
70+
* -------------------------------------------------------------------------- */
71+
72+
:root {
73+
--vp-custom-block-tip-border: var(--vp-c-brand);
74+
--vp-custom-block-tip-text: var(--vp-c-brand-darker);
75+
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
76+
}
77+
78+
.dark {
79+
--vp-custom-block-tip-border: var(--vp-c-brand);
80+
--vp-custom-block-tip-text: var(--vp-c-brand-lightest);
81+
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
82+
}
83+
84+
/**
85+
* Component: Algolia
86+
* -------------------------------------------------------------------------- */
87+
88+
.DocSearch {
89+
--docsearch-primary-color: var(--vp-c-brand) !important;
90+
}
91+

docs/configmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Configmap
1+
# ConfigMap
22

33
上面的教程提到,我们在不同环境 `dev` `test` `uat` `prod` 中区分资源,可以让其资源独立互相不受影响,但是随之而来也会带来一些问题,例如不同环境的数据库的地址往往是不一样的,那么如果在代码中写同一个数据库的地址,就会出现问题。
44

docs/container.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Container
1+
# Container
22

33
我们的旅程从一段代码开始。新建一个 `main.go` 文件,复制下面的代码到文件中。
44

docs/dashboard.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Dashboard
1+
# Dashboard
22

3-
### kubernetes dashboard
3+
## kubernetes dashboard
44

55
> Dashboard 是基于网页的 Kubernetes 用户界面。 你可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用排错,还能管理集群资源。 你可以使用 Dashboard 获取运行在集群中的应用的概览信息,也可以创建或者修改 Kubernetes 资源 (如 Deployment,Job,DaemonSet 等等)。 例如,你可以对 Deployment 实现弹性伸缩、发起滚动升级、重启 Pod 或者使用向导创建新的应用。
66
@@ -12,7 +12,7 @@ minikube dashboard
1212

1313
![eB3MYd](https://cdn.jsdelivr.net/gh/guangzhengli/PicURL@master/uPic/eB3MYd.png)
1414

15-
### K9s
15+
## K9s
1616

1717
[K9s](https://k9scli.io/) 是一个基于 Terminal 的轻量级 UI,可以更加轻松的观察和管理已部署的 k8s 资源。使用方式非常简单,安装后输入 `k9s` 即可开启 Terminal Dashboard,更多用法可以参考官网。
1818

docs/deployment.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
## Deployment
1+
# Deployment
22

33
在生产环境中,我们基本上不会直接管理 pod,我们需要 `kubernetes` 来帮助我们来完成一些自动化操作,例如自动扩容或者自动升级版本。可以想象在生产环境中,我们手动部署了 10 个 `hellok8s:v1` 的 pod,这个时候我们需要升级成 `hellok8s:v2` 版本,我们难道需要一个一个的将 `hellok8s:v1` 的 pod 手动升级吗?
44

55
这个时候就需要我们来看 `kubeates` 的另外一个资源 `deployment`,来帮助我们管理 pod。
66

7-
### 扩容
7+
## 扩容
88

99
首先可以创建一个 `deployment.yaml` 的文件。来管理 `hellok8s` pod。
1010

@@ -83,7 +83,7 @@ spec:
8383

8484
![deployment](https://cdn.jsdelivr.net/gh/guangzhengli/PicURL@master/uPic/deployment.png)
8585

86-
### 升级版本
86+
## 升级版本
8787

8888
我们接下来尝试将所有 `v1` 版本的 `pod` 升级到 `v2` 版本。首先我们需要构建一份 `hellok8s:v2` 的版本镜像。唯一的区别就是字符串替换成了 `[v2] Hello, Kubernetes!`。
8989

@@ -155,7 +155,7 @@ curl http://localhost:3000
155155

156156
你也可以输入 `kubectl describe pod hellok8s-deployment-66799848c4-kpc6q` 来看是否是 `v2` 版本的镜像。
157157

158-
### Rolling Update(滚动更新)
158+
## Rolling Update(滚动更新)
159159

160160
如果我们在生产环境上,管理着多个副本的 `hellok8s:v1` 版本的 pod,我们需要更新到 `v2` 的版本,像上面那样的部署方式是可以的,但是也会带来一个问题,就是所有的副本在同一时间更新,这会导致我们 `hellok8s` 服务在短时间内是不可用的,因为所有 pod 都在升级到 `v2` 版本的过程中,需要等待某个 pod 升级完成后才能提供服务。
161161

@@ -221,7 +221,7 @@ spec:
221221

222222
![rollingupdate](https://cdn.jsdelivr.net/gh/guangzhengli/PicURL@master/uPic/rollingupdate.png)
223223

224-
### 存活探针 (livenessProb)
224+
## 存活探针 (livenessProb)
225225

226226
> 存活探测器来确定什么时候要重启容器。 例如,存活探测器可以探测到应用死锁(应用程序在运行,但是无法继续执行后面的步骤)情况。 重启这种状态下的容器有助于提高应用的可用性,即使其中存在缺陷。-- [LivenessProb](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
227227

@@ -347,7 +347,7 @@ kubectl describe pod hellok8s-68f47f657c-zwn6g
347347
# Warning BackOff 2m41s (x36 over 10m) kubelet Back-off restarting failed container
348348
```
349349

350-
### 就绪探针 (readiness)
350+
## 就绪探针 (readiness)
351351

352352
> 就绪探测器可以知道容器何时准备好接受请求流量,当一个 Pod 内的所有容器都就绪时,才能认为该 Pod 就绪。 这种信号的一个用途就是控制哪个 Pod 作为 Service 的后端。 若 Pod 尚未就绪,会被从 Service 的负载均衡器中剔除。-- [ReadinessProb](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
353353

docs/helm.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Helm
1+
# Helm
22

33
经过前面的教程,想必你已经对 kubernetes 的使用有了一定的理解。但是不知道你是否想过这样一个问题,就是我们前面教程中提到的所有资源,包括用 `pod`, `deployment`, `service`, `ingress`, `configmap`,`secret` 所有资源来部署一套完整的 `hellok8s` 服务的话,难道需要一个一个的 `kubectl apply -f` 来创建吗?如果换一个 namespace,或者说换一套 kubernetes 集群部署的话,又要重复性的操作创建的过程吗?
44

@@ -22,7 +22,7 @@ brew install helm
2222

2323
Helm 的使用方式可以解释为:Helm 安装 *charts* 到 Kubernetes 集群中,每次安装都会创建一个新的 *release*。你可以在 Helm 的 chart *repositories* 中寻找新的 chart。
2424

25-
### 用 helm 安装 hellok8s
25+
## 用 helm 安装 hellok8s
2626
开始本节教程前,我们先把之前手动创建的 hellok8s 相关的资源删除(防止使用 helm 创建同名的 k8s 资源失败)。
2727

2828
在尝试自己创建 hellok8s helm chart 之前,我们可以先来熟悉一下怎么使用 helm chart。在这里我先创建好了一个 hellok8s(包括会创建 deployment, service, ingress, configmaps, secret)的 helm chart。通过 GitHub actions 生成放在了 [gh-pages](https://github.com/guangzhengli/k8s-tutorials/tree/gh-pages/) 分支下的 `index.yaml` 文件中。
@@ -79,7 +79,7 @@ curl http://192.168.59.100/hello
7979
# [v6] Hello, Helm! Message from helm values: It works with Helm Values[v2]!, From namespace: default, From host: hellok8s-deployment-598bbd6884-ttk78, Get Database Connect URL: http://DB_ADDRESS_DEFAULT, Database Connect Password: db_password
8080
```
8181

82-
### 创建 helm charts
82+
## 创建 helm charts
8383

8484
在使用已经创建好的 hello-helm charts 来创建整个 hellok8s 资源后,你可能还是有很多的疑惑,包括 Chart 是如何生成和发布的,如何创建一个新的 Chart?在这节教程中,我们会尝试自己来创建 hello-helm Chart 来完成之前的操作。
8585

@@ -177,7 +177,7 @@ application:
177177
178178
例如之前教程中,将环境变量 `DB_URL` 定义在 k8s configmaps 中,那么该资源可以定义成如文件所示 `hellok8s-configmaps.yaml`。其中 `metadata.name` 的值是 `{{ .Values.application.name }}-config`,意思是从 `values.yaml` 文件中获取 `application.name` 的值 `hellok8s`,拼接 `-config` 字符串,这样创建出来的 configmaps 资源名称就是 `hellok8s-config`。
179179

180-
同理 `{{ .Values.application.hellok8s.database.url }}` 就是获取值为 `http://DB_ADDRESS_DEFAULT` 放入 configmaps 对应 key 为 DB_URL 的 value 中。
180+
同理 `{{ .Values.application.hellok8s.database.url }}` 就是获取值为 `http://DB_ADDRESS_DEFAULT` 放入 configmaps 对应 key 为 DB_URL 的 value 中。
181181

182182
```yaml
183183
apiVersion: v1
@@ -312,7 +312,7 @@ kubectl get pods
312312
# nginx-deployment-d47fd7f66-tsqj5 1/1 Running 0 32m
313313
```
314314

315-
#### rollback
315+
## rollback
316316

317317
Helm 也提供了 Rollback 的功能,我们先修改一下 `message: "It works with Helm Values[v2]!"` 加上 [v2]。
318318
@@ -363,7 +363,7 @@ curl http://192.168.59.100/hello
363363
# [v6] Hello, Helm! Message from helm values: It works with Helm Values!, From namespace: default, From host: hellok8s-deployment-57d7df7964-482xw, Get Database Connect URL: http://DB_ADDRESS_DEFAULT, Database Connect Password: db_password
364364
```
365365

366-
#### 多环境配置
366+
## 多环境配置
367367

368368
使用 Helm 也很容易多环境部署,新建 `values-dev.yaml` 文件,里面内容自定义 `dev` 环境需要的配置信息。
369369

@@ -401,7 +401,7 @@ kubectl get pods -n dev
401401

402402
除此之外,还可以使用 '--set-file' 设置独立的值,类似于 `helm upgrade --install hello-helm -f values.yaml -f values-dev.yaml --set application.hellok8s.message="It works with set helm values" -n dev .` 方式在命令中设置 values 的值,可以随意修改相关配置,此方法在 CICD 中经常用到。
403403

404-
### helm chart 打包和发布
404+
## helm chart 打包和发布
405405

406406
上面的例子展示了我们可以用一行命令在一个新的环境中安装所有需要的 k8s 资源!那么如何将 helm chart 打包、分发和下载呢?在官网中,提供了两种教程,一种是以 [GCS 存储的教程](https://helm.sh/zh/docs/howto/chart_repository_sync_example/),还有一种是以 [GitHub Pages 存储的教程](https://helm.sh/zh/docs/howto/chart_releaser_action/)。
407407

docs/ingress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## ingress
1+
# Ingress
22

33
[Ingress](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#ingress-v1beta1-networking-k8s-io) 公开从集群外部到集群内[服务](https://kubernetes.io/docs/concepts/services-networking/service/)的 HTTP 和 HTTPS 路由。 流量路由由 Ingress 资源上定义的规则控制。Ingress 可为 Service 提供外部可访问的 URL、负载均衡流量、 SSL/TLS,以及基于名称的虚拟托管。你必须拥有一个 [Ingress 控制器](https://kubernetes.io/zh-cn/docs/concepts/services-networking/ingress-controllers) 才能满足 Ingress 的要求。 仅创建 Ingress 资源本身没有任何效果。 [Ingress 控制器](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers) 通常负责通过负载均衡器来实现 Ingress,例如 `minikube` 默认使用的是 [nginx-ingress](https://minikube.sigs.k8s.io/docs/tutorials/nginx_tcp_udp_ingress/),目前 `minikube` 也支持 [Kong-Ingress](https://minikube.sigs.k8s.io/docs/handbook/addons/kong-ingress/)。
44

docs/job.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Job
1+
# Job
22

33
在实际的开发过程中,还有一类任务是之前的资源不能满足的,即一次性任务。例如常见的计算任务,只需要拿到相关数据计算后得出结果即可,无需一直运行。而处理这一类任务的资源就是 Job。
44

0 commit comments

Comments
 (0)