Skip to content

Commit

Permalink
GITBOOK-195: No subject
Browse files Browse the repository at this point in the history
  • Loading branch information
mouuii authored and gitbook-bot committed Dec 21, 2024
1 parent 9c4a5bb commit a8d62d0
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 8 deletions.
Binary file added .gitbook/assets/1734748395130.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/1734748990526.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (1) (1) (1) (1) (1) (1) (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (1) (1) (1) (1) (1) (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (1) (1) (1) (1) (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (1) (1) (1) (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (1) (1) (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (1) (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

* [ansible 教程](ping-tai-gong-cheng-xun-lian-ying-yi-qi/ansible-jiao-cheng/README.md)
* [01- ansible 介绍](ping-tai-gong-cheng-xun-lian-ying-yi-qi/ansible-jiao-cheng/01-ansible-jie-shao.md)
* [02-使用 kubespray安装 k8s集群](ping-tai-gong-cheng-xun-lian-ying-yi-qi/ansible-jiao-cheng/02-shi-yong-kubespray-an-zhuang-k8s-ji-qun.md)
* [helm 教程](ping-tai-gong-cheng-xun-lian-ying-yi-qi/helm-jiao-cheng/README.md)
* [01-快速入门](ping-tai-gong-cheng-xun-lian-ying-yi-qi/helm-jiao-cheng/01.md)
* [02-如何使用](ping-tai-gong-cheng-xun-lian-ying-yi-qi/helm-jiao-cheng/02.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 07-workqueue

<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

今天我们来详细研究下 workqueue 相关代码。client-go 的 util/workqueue 包里主要有三个队列,分别是普通队列,延时队列,限速队列,后一个队列以前一个队列的实现为基础,层层添加新功能,我们按照 Queue、DelayingQueue、RateLimitingQueue 的顺序层层拨开来看限速队列是如何实现的。

Expand Down Expand Up @@ -419,7 +419,7 @@ func (r *TypedBucketRateLimiter[T]) Forget(item T) {

```

<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

令牌桶算法内部实现了一个存放token(令牌)的“桶”,初始时“桶”是空的,token会以固定速率往“桶”里填充,直到将其填满为止,多余的token会被丢弃。每个元素都会从令牌桶得到一个token,只有得到token的元素才允许通过(accept),而没有得到token的元素处于等待状态。令牌桶算法通过控制发放token来达到限速目的。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: controller

比如当某个Pod出现故障时,Deployment Controller会及时发现故障并执行自动化修复流程,确保集群里的Pod始终处于预期的工作状态。

<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

## 工作原理

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,5 +746,5 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
}
</code></pre>

<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ kubectl delete deployment nginx-deployment --cascade=orphan

### GarbageCollector 架构图 <a href="#garbagecollector" id="garbagecollector"></a>

<figure><img src="../../.gitbook/assets/image (1) (1).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../../.gitbook/assets/image (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

<pre class="language-go"><code class="lang-go"><strong>// GarbageCollector 对象表示垃圾回收控制器,是实现垃圾回收功能的核心对象。
</strong><strong>// 通过 reflector 监视受管API对象的更改,将结果汇集到单线程的dependencyGraphBuilder中
Expand Down Expand Up @@ -161,7 +161,7 @@ B对应一个node,owner列表里有A,dependent列表里有C;
C对应一个node,owner列表里有B,无dependent。
```
<figure><img src="../../.gitbook/assets/image (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
#### **2个处理器**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 02-使用 kubespray安装 k8s集群

## &#x20;常见集群部署方式

在Kubernetes(K8s)中部署集群的方式多种多样,根据环境和需求的不同,常见的部署方式包括:

1. **手动二进制部署**
* 从零开始手动配置每个节点上的所有组件。这包括安装Docker或容器运行时、设置网络插件、安装etcd集群、配置kube-apiserver、kube-controller-manager、kube-scheduler等控制面组件,并启动kube-proxy与kubelet服务。这种方式需要对Kubernetes架构有深入理解,适用于学习和实验场景。
2. **kubeadm部署**
* `kubeadm`是Kubernetes官方提供的工具,用于快速搭建生产级别的Kubernetes集群。它简化了初始化Master节点以及加入Worker节点的过程,可以方便地创建一个最小化的高可用集群。
3. **第三方自动化部署工具**
* Kubespray(Ansible playbook驱动的部署工具):通过Ansible Playbooks自动化执行一系列步骤来部署Kubernetes集群,适用于生产环境,方便快捷。

## Kubespray

### 介绍

Kubespray 是一个开源项目,旨在帮助用户在多云环境中部署和管理Kubernetes集群。为了实现这个目标,Kubespray 使用了 Ansible 这个强大的工具。Ansible 是一个深受信赖的开源自动化运维工具,主要用于自动化应用部署、配置管理和任务执行。基于此,Kubespray 能够在各种云平台,如 AWS、GCE、Azure、OpenStack 等以及裸机等硬件上进行部署。

使用 Kubespray,用户可以选择执行一个 Ansible 脚本,然后 Ansible 会使用 SSH 协议与各个目标主机进行通信,并基于该脚本实现集群部署、清理、升级等任务。

<figure><img src="../../.gitbook/assets/image.png" alt=""><figcaption></figcaption></figure>

### 安装

#### 克隆代码

```
git clone [email protected]:kubernetes-sigs/kubespray.git
```

#### 安装 ansible

需要提前安装下 python 和 pip , 以下命令主要是创建一个 python 虚拟环境,并安装依赖,复制命令执行即可

```sh
VENVDIR=kubespray-venv
KUBESPRAYDIR=kubespray
python3 -m venv $VENVDIR
source $VENVDIR/bin/activate
cd $KUBESPRAYDIR
pip install -U -r requirements.txt
```

### 配置 inventory

将项目中 sample 文件夹目录拷贝一份,然后修改里面的主机和配置:

```
cp -r inventory/sample inventory/mycluster
```

我使用了2台虚拟机,你可以参考我的写法和命令:

<figure><img src="../../.gitbook/assets/1734748990526.png" alt=""><figcaption></figcaption></figure>

<figure><img src="../../.gitbook/assets/1734748395130.png" alt=""><figcaption></figcaption></figure>

4 changes: 2 additions & 2 deletions readme/1-zai-k8s-shang-bu-shu-ying-yong.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1 在 k8s 上部署应用
# 在 k8s 上部署应用

## 1.1 为什么需要容器

Expand All @@ -14,7 +14,7 @@ Kubernetes 是一个用于部署容器的平台。所有部署到 Kubernetes 的

这就引出了容器。容器是一种只打包你的应用程序及其所需的依赖,然后在一个隔离的环境中运行的方式,就像虚拟机一样,但不需要安装和管理操作系统。

<figure><img src="../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>

## 1.2 容器的好处

Expand Down

0 comments on commit a8d62d0

Please sign in to comment.