安装docker
yum install -y epel-release
yum install -y docker
systemctl start docker
修改Docker镜像源为国内源
编辑/etc/docker/daemon.json
,添加如下内容:
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
然后执行:
systemctl restart docker
重启Docker服务。
在各个节点建立自定义账户,使其可以用命令操作docker
- 查看docker.sock文件的用户组
[root@localhost rke]# ls -al /var/run/docker.sock
srw-rw---- 1 root root 0 Oct 29 04:41 /var/run/docker.sock
可以发现docker.sock属于root组,需要将新建立的用户加入root组。(新版docker的docker.sock文件属于docker用户组,故需要将新用户加入到docker用户组而不是root)
- 建立用户
useradd rancher
usermod -G root rancher
- 尝试使用rancher用户操作docker,观察是否有权限。
su rancher
docker info
配置主节点到各个节点rancher用户的免密登录
ssh-keygen
ssh-copy-id rancher@节点IP
注意,应使用能够操作docker的用户(非root)做免密。在这个例子中使用rancher用户。
下载RKE
下载链接:https://rancher.com/docs/rke/latest/en/installation/
使用rke配置集群
./rke_linux-amd64 config
按照向导提示的操作:
[+] Cluster Level SSH Private Key Path [~/.ssh/id_rsa]: 使用~/.ssh/id_rsa
[+] Number of Hosts [1]: 集群主机个数
[+] SSH Address of host (1) [none]: 主机1地址
[+] SSH Port of host (1) [22]: SSH端口
[+] SSH Private Key Path of host (10.180.210.237) [none]: 使用~/.ssh/id_rsa
[+] SSH User of host (10.180.210.237) [ubuntu]: SSH用户名,这里使用rancher
[+] Is host (10.180.210.237) a Control Plane host (y/n)? [y]: 是否运行Control Plane
[+] Is host (10.180.210.237) a Worker host (y/n)? [n]: 是否是worker
[+] Is host (10.180.210.237) an etcd host (y/n)? [n]: 是否运行etcd
[+] Override Hostname of host (10.180.210.237) [none]: 是否重设hostname
[+] Internal IP of host (10.180.210.237) [none]: 主机内部IP
[+] Docker socket path on host (10.180.210.237) [/var/run/docker.sock]: docker sock路径,使用默认
[+] SSH Address of host (2) [none]: 主机2的配置,后续配置相同,不再赘述
......
[+] Network Plugin Type (flannel, calico, weave, canal) [canal]: 网络插件类型
[+] Authentication Strategy [x509]: 认证策略
[+] Authorization Mode (rbac, none) [rbac]: 认证模式
[+] Kubernetes Docker image [rancher/hyperkube:v1.15.5-rancher1]: k8s镜像名
[+] Cluster domain [cluster.local]: 集群域名
[+] Service Cluster IP Range [10.43.0.0/16]: 集群内服务IP的范围
[+] Enable PodSecurityPolicy [n]: pod安全策略
[+] Cluster Network CIDR [10.42.0.0/16]: 集群网络范围
[+] Cluster DNS Service IP [10.43.0.10]: 集群DNS的IP
[+] Add addon manifest URLs or YAML files [no]: 是否增加插件manifest URL或配置文件
安装并启动集群
配置向导操作完毕后,执行如下命令:
./rke_linux-amd64 up
启动kubernetes集群。
安装kubectl
下载kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
复制RKE可执行文件所在目录下生成的kube_config_cluster.yml
到~/.kube/config
cp kube_config_cluster.yml ~/.kube/config
验证集群安装
执行
kubectl get nodes
kubectl get pods -n kube-system
如果看到类似如下输出,说明配置成功。
[root@localhost rke]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
10.180.210.172 Ready controlplane,etcd,worker 54m v1.15.5
10.180.210.237 Ready worker 54m v1.15.5
[root@localhost rke]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
canal-8hn9h 2/2 Running 0 20m
canal-w8bqz 2/2 Running 0 20m
coredns-799dffd9c4-pdkjf 1/1 Running 0 20m
coredns-autoscaler-84766fbb4-vthml 1/1 Running 0 20m
metrics-server-59c6fd6767-s66hn 1/1 Running 0 20m
rke-coredns-addon-deploy-job-wsppz 0/1 Completed 0 20m
rke-ingress-controller-deploy-job-thzlg 0/1 Completed 0 20m
rke-metrics-addon-deploy-job-q2cpj 0/1 Completed 0 20m
rke-network-plugin-deploy-job-99zr5 0/1 Completed 0 20m
网友评论