Skip to content

Commit cd9ca4c

Browse files
mouuiigitbook-bot
authored andcommitted
GITBOOK-196: No subject
1 parent a8d62d0 commit cd9ca4c

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

Diff for: ping-tai-gong-cheng-xun-lian-ying-yi-qi/ansible-jiao-cheng/02-shi-yong-kubespray-an-zhuang-k8s-ji-qun.md

+40-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,28 @@ Kubespray 是一个开源项目,旨在帮助用户在多云环境中部署和
2323

2424
### 安装
2525

26-
#### 克隆代码
26+
#### 1. 设置免密登录
27+
28+
首先在你的 Ansible 节点上为你的本地用户生成 SSH 密钥:
29+
30+
```
31+
$ ssh-keygen
32+
```
33+
34+
使用 `ssh-copy-id` 命令复制 SSH 密钥:
35+
36+
```
37+
$ ssh-copy-id -i ~/.ssh/{rsa.pub} {username}@{192.168.1.241}
38+
$ ssh-copy-id -i ~/.ssh/{rsa.pub} {username}@{192.168.1.242}
39+
```
40+
41+
#### 2. 克隆代码
2742

2843
```
2944
git clone [email protected]:kubernetes-sigs/kubespray.git
3045
```
3146

32-
#### 安装 ansible
47+
#### 3. 安装 ansible
3348

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

@@ -56,3 +71,26 @@ cp -r inventory/sample inventory/mycluster
5671

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

74+
### 安装集群
75+
76+
```
77+
ansible-playbook -i inventory/mycluster/inventory.ini cluster.yml -b -v \
78+
--private-key=~/.ssh/private_key -u xx -e ansible_become_pass=xxxx
79+
```
80+
81+
### 访问集群
82+
83+
`kubectl_localhost: true``kubeconfig_localhost: true`&#x20;
84+
85+
如果启用了`kubectl_localhost``kubectl`将下载到`/usr/local/bin/`,还会生成一个`inventory/mycluster/artifacts/kubectl.sh` 脚本
86+
87+
如果`kubeconfig_localhost`启用了`admin.conf`会出现在 `inventory/mycluster/artifacts/`
88+
89+
注意:admin.conf 文件中的控制器主机名可能是私有 IP。如果是这样,请将其更改为使用控制器的公共 IP 或集群的负载均衡器。&#x20;
90+
91+
您可以通过运行以下命令查看节点列表:
92+
93+
```
94+
cd inventory/mycluster/artifacts
95+
./kubectl.sh get nodes
96+
```

0 commit comments

Comments
 (0)