Ansible 二进制部署k8s

主机信息

 

主机IP   主机名 角色
192.168.124.61 master kube-apiserver,kube-controller-manager,kube-scheduler,etcd
192.168.124.62 node1 kubelet,kube-proxy,etcd
192.168.124.63 node2 kubelet,kube-proxy,etcd

 

 

 

 

 

安装ansible

yum install ansible -y

 修改配置文件,增加节点

vi  /etc/ansible/hosts 
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern you can specify
# them like this:

## www[001:006].example.com
[k8s]
192.168.124.61
192.168.124.62
192.168.124.63

[k8s:vars]
ansible_ssh_user=root 
ansible_ssh_pass=123456
ansible_ssh_port=22



# Ex 3: A collection of database servers in the 'dbservers' group

## [dbservers]
## 
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here's another example of host ranges, this time there are no
# leading 0s:

 

  

配置免密登录

1、生产秘钥

ssh-keygen -t rsa

2、分发秘钥

ansible k8s -m  authorized_key -a "user=root key='{{lookup('file','/root/.ssh/id_rsa.pub')}}'"

 

上传文件 

ansible 文件

链接:https://pan.baidu.com/s/1OFIPFEWxh5R4SEPGgN0aIg
提取码:6a83

  

修改文件里面的ip,安装目录等

 最新修改:安装网络插件为flannel  host-gw模式,采用ipvs。

查看README.md 文件,根据实际路径等进行修改

执行安装命令

单Master版:

# ansible-playbook -i hosts single-master-deploy.yml -uroot -k

 

 

查看执行结果

 

查看etcd

/opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/etcd.pem --key-file=/opt/etcd/ssl/etcd-key.pem  --endpoints="https://192.168.124.61:2379,https://192.168.124.62:2379,https://192.168.124.63:2379"  cluster-health

  

登录

 

 

 选择token,复制里面的taoken

 

 

 

 

查看部署状态

[root@master k8s]# kubectl get all --all-namespaces
NAMESPACE              NAME                                             READY   STATUS    RESTARTS   AGE
ingress-nginx          pod/nginx-ingress-controller-mgkcx               1/1     Running   0          7m35s
ingress-nginx          pod/nginx-ingress-controller-xx79x               1/1     Running   0          7m34s
kube-system            pod/coredns-5675d5b4d-nhjnp                      1/1     Running   0          7m47s
kube-system            pod/kube-flannel-ds-amd64-kbngx                  1/1     Running   0          7m44s
kube-system            pod/kube-flannel-ds-amd64-r552t                  1/1     Running   0          7m44s
kubernetes-dashboard   pod/dashboard-metrics-scraper-66b49655d4-5bhk7   1/1     Running   0          7m44s
kubernetes-dashboard   pod/kubernetes-dashboard-5b8d566858-c7q92        1/1     Running   0          7m44s

NAMESPACE              NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
default                service/kubernetes                  ClusterIP   10.254.0.1       <none>        443/TCP          12m
ingress-nginx          service/ingress-nginx               ClusterIP   10.254.128.96    <none>        80/TCP,443/TCP   7m46s
kubernetes-dashboard   service/dashboard-metrics-scraper   ClusterIP   10.254.111.247   <none>        8000/TCP         7m44s
kubernetes-dashboard   service/kubernetes-dashboard        NodePort    10.254.44.153    <none>        443:30001/TCP    7m45s

NAMESPACE       NAME                                      DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
ingress-nginx   daemonset.apps/nginx-ingress-controller   2         2         2       2            2           <none>          7m46s
kube-system     daemonset.apps/kube-flannel-ds-amd64      2         2         2       2            2           <none>          7m46s

NAMESPACE              NAME                                        READY   UP-TO-DATE   AVAILABLE   AGE
kube-system            deployment.apps/coredns                     1/1     1            1           7m48s
kubernetes-dashboard   deployment.apps/dashboard-metrics-scraper   1/1     1            1           7m44s
kubernetes-dashboard   deployment.apps/kubernetes-dashboard        1/1     1            1           7m44s

NAMESPACE              NAME                                                   DESIRED   CURRENT   READY   AGE
kube-system            replicaset.apps/coredns-5675d5b4d                      1         1         1       7m47s
kubernetes-dashboard   replicaset.apps/dashboard-metrics-scraper-66b49655d4   1         1         1       7m44s
kubernetes-dashboard   replicaset.apps/kubernetes-dashboard-5b8d566858        1         1         1       7m44s

  

 

posted @ 2020-06-01 17:20  执酒  阅读(604)  评论(0编辑  收藏  举报