Ansible automation deployment k8s-1.16.0 cluster

                         Ansible automatic deployment k8s binary cluster

Ansible is an it automation tool. It can configure systems, deploy software, and coordinate more advanced IT tasks, such as continuous deployment and rolling update. Ansible is suitable for managing enterprise IT infrastructure. Here I use ansible to realize the automatic deployment of Kubernetes v1.16 high availability cluster (offline version) (but I still need the network, because I need to deploy the flannel,coredns,ingress,dashboard plug-ins, and pull the image

Ansible automation deployment k8s-1.16.0 cluster
introduce

Using ansible automation to deploy k8s cluster (support single master, multi master) offline version
Software architecture

Software architecture description
Single master architecture

Multi master architecture

1. Installation tutorial

First deploy an Ansible to be the control node. The installation steps are omitted here
 Extract both files to the ansible server. My working directory is under / opt /. Put all the extracted directories under / opt
 Modify the hosts file, specify whether the deployment is single master or multi master, and all variables under group VaR, and specify the ip to be modified

2. Instructions

Single master,4c,8g,(1 master,2 nodes, 1 ansible)
Multi master,4c,8g,(2 masters, 2 nodes, 1 ansible,2 nginx)
If you are deploying multiple master hosts, you need to run another keepalived on nginx. If you are a virtual machine, you can use slb as a supplement

1. System initialization

  1. Close selinux, firewalld
  2. Close swap
  3. time synchronization
  4. Write hosts
    2. Etcd cluster deployment
  5. Generate etcd certificate
  6. Deploy three etcd clusters
  7. View cluster status
    1. Deploying Master
  8. Generate apiserver certificate
  9. Deploying the apiserver, controller manager, and scheduler components
  10. Start TLS Bootstrapping
    1. Deploying Node
  11. Install Docker
  12. Deploy kubelet and Kube proxy
  13. Allow issuing certificates for new nodes on Master
  14. Authorize apiserver to access kubelet
    1. Deploy plug-ins (ready to mirror)
  15. Flannel
  16. Web UI
  17. CoreDNS
  18. Ingress Controller
    1. Master high availability
  19. Add Master node (consistent with Master1)
  20. Deploy Nginx load balancer
  21. Nginx + preserved high availability
  22. Modify Node connection VIP

3. Deployment Analysis of K8S components organized by roles

Suggestions:

  1. Process and Roles structure
  2. If the configuration file has unfixed content, use jinja rendering
  3. The contents of manual intervention changes shall be uniformly written in one file

Download required files

Make sure all nodes have the same system time

4. Download Ansible deployment file:

git clone git@gitee.com:zhaocheng172/ansible-k8s.git

When you pull the code, please send me your public key, otherwise you can't pull it down
Download and unzip the package:
https://pan.baidu.com/s/1Wf9sFR4zkpx_D0BJbZK7ZQ

tar zxf binary_pkg.tar.gz

Modify Ansible file

Modify the hosts file and modify the corresponding IP and name according to the plan.

vi hosts

Modify the group? Vars / all.yml file, modify the package directory and certificate trusted IP.
vim group_vars/all.yml
software_dir: '/root/binary_pkg'
...
cert_hosts:
k8s:
etcd:

5. One click deployment

Single Master version
ansible-playbook -i hosts single-master-deploy.yml -uroot -k
Multi Master:
ansible-playbook -i hosts multi-master-deploy.yml -uroot -k

6. Deployment control

If the installation of a phase fails, targeted testing

For example: run deployment plug-ins only
ansible-playbook -i hosts single-master-deploy.yml -uroot -k --tags master

Effect after deployment

[root@k8s-master1 ~]# kubectl get node
NAME          STATUS   ROLES    AGE    VERSION
k8s-master1   Ready    <none>   2d3h   v1.16.0
k8s-node1     Ready    <none>   2d3h   v1.16.0
k8s-node2     Ready    <none>   2d3h   v1.16.0
[root@k8s-master1 ~]# kubectl get cs
NAME                 AGE
controller-manager   <unknown>
scheduler            <unknown>
etcd-2               <unknown>
etcd-0               <unknown>
etcd-1               <unknown>
[root@k8s-master1 ~]# kubectl get pod,svc -A
NAMESPACE              NAME                                             READY   STATUS    RESTARTS   AGE
ingress-nginx          pod/nginx-ingress-controller-8zp8r               1/1     Running   0          2d3h
ingress-nginx          pod/nginx-ingress-controller-bfgj6               1/1     Running   0          2d3h
ingress-nginx          pod/nginx-ingress-controller-n5k22               1/1     Running   0          2d3h
kube-system            pod/coredns-59fb8d54d6-n6m5w                     1/1     Running   0          2d3h
kube-system            pod/kube-flannel-ds-amd64-jwvw6                  1/1     Running   0          2d3h
kube-system            pod/kube-flannel-ds-amd64-m92sg                  1/1     Running   0          2d3h
kube-system            pod/kube-flannel-ds-amd64-xwf2h                  1/1     Running   0          2d3h
kubernetes-dashboard   pod/dashboard-metrics-scraper-566cddb686-smw6p   1/1     Running   0          2d3h
kubernetes-dashboard   pod/kubernetes-dashboard-c4bc5bd44-zgd82         1/1     Running   0          2d3h

NAMESPACE              NAME                                TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
default                service/kubernetes                  ClusterIP   10.0.0.1     <none>        443/TCP          2d3h
ingress-nginx          service/ingress-nginx               ClusterIP   10.0.0.22    <none>        80/TCP,443/TCP   2d3h
kube-system            service/kube-dns                    ClusterIP   10.0.0.2     <none>        53/UDP,53/TCP    2d3h
kubernetes-dashboard   service/dashboard-metrics-scraper   ClusterIP   10.0.0.176   <none>        8000/TCP         2d3h
kubernetes-dashboard   service/kubernetes-dashboard        NodePort    10.0.0.72    <none>        443:30001/TCP    2d3h

Tags: Linux ansible Nginx Kubernetes git

Posted on Mon, 09 Dec 2019 20:26:11 -0500 by evildobbi