In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Ansible Automated deployment of K8s binary Cluster
Ansible is an IT automation tool. It can configure the system, deploy software, and coordinate more advanced IT tasks, such as continuous deployment and rolling updates. Ansible is suitable for managing the enterprise IT infrastructure. Here I use Ansible to implement Kubernetes v1.16 high availability cluster automatic deployment (offline version) (but still need network, because here need to deploy flannel,coredns,ingress,dashboard plug-in, need to pull image
Ansible Automated deployment of k8s-1.16.0 Cluster
Introduction
Using ansible to automate the deployment of k8s cluster (supports single master, multiple master) offline version
Software architecture
Software architecture description
Single master architecture
Multi-master architecture
1. Installation tutorial
First deploy an Ansible to manage and control the node. Omit the installation steps here and extract both files to the ansible server. My working directory is under / opt/. Put all the extracted directories under / opt to modify the hosts file, specify whether to deploy a single master or multiple master, and the variable of all under group_var, and specify the ip that needs to be modified.
two。 instructions
Single master,4c,8g, (1 master,2, node,1, ansible) multiple master,4c,8g, (2 master,2, node,1, ansible,2, nginx) if you are deploying multiple master hosts, you need to run another keepalived on the nginx. If it is a CVM, you can supplement it with slb.
1. System initialization
Turn off selinux,firewalld turn off swap time synchronization write hosts
2. Etcd cluster deployment generates etcd certificates deploy three etcd clusters to view cluster status
3. Deploy Master to generate apiserver certificates deploy apiserver, controller-manager and scheduler components to start TLS Bootstrapping
4. Deploy Node install Docker deploy kubelet and kube-proxy allow issuing certificates for new Node to authorize apiserver access to kubelet on Master
5. Deploy plug-ins (ready for image) FlannelWeb UICoreDNSIngress Controller
6. Master High availability add Master nodes (consistent with Master1) deploy Nginx load balancer Nginx+Keepalived High availability modified Node connection VIP
7. Automatic expansion of node nodes triggers the addition of Node. You need to know if you want to add another node. Call the Ansible script to deploy components, how to prepare this node, whether the new machine is ready, and whether these components are deployed. Check whether the service is available, and the newly added components check whether it is normal to call API to add the new Node to the cluster or enable Node to join the cluster automatically to observe the new Node status, monitor, observe the new node, running logs, and resource status. Complete Node expansion and receive new Pod
Deployment Analysis of components of K8S in 3.Roles Organization
Write recommendations:
Combing process and Roles structure if the configuration file has irregular content, the contents of manual intervention changes using jinja rendering should be written into one file.
Download the required files
Ensure that the system time of all nodes is the same
4. Download the Ansible deployment file:
Git clone git@gitee.com:zhaocheng172/ansible-k8s.git
When you pull the substitution code, please send me your public key, or you won't be able to pull it down.
Download the package and extract it:
Https://pan.baidu.com/s/1Wf9sFR4zkpx_D0BJbZK7ZQ
Tar zxf binary_pkg.tar.gz
Modify the 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 nic Nic address and certificate to trust IP.
Vim group_vars/all.ymlnic: eth0 writes k8s according to his network card: trusted ip
5. One-click deployment
Single Master version
Ansible-playbook-I hosts single-master-deploy.yml-uroot-k
Multi-Master version:
Ansible-playbook-I hosts multi-master-deploy.yml-uroot-k
6. Deployment control
If a certain stage of installation fails, targeted testing can be carried out.
For example: only run the deployment plug-in
Ansible-playbook-I hosts single-master-deploy.yml-uroot-k-- tags master
Deployment effect of single master
[root@k8s-master1 ~] # kubectl get nodeNAME STATUS ROLES AGE VERSIONk8s-master1 Ready 2d3h v1.16.0k8s-node1 Ready 2d3h v1.16.0k8s-node2 Ready 2d3h v1.16.0 [root@k8s-master1 ~] # kubectl get csNAME AGEcontroller-manager scheduler etcd-2 etcd-0 etcd-1 [root@k8s-master1 ~] # kubectl get pod Svc-ANAMESPACE NAME READY STATUS RESTARTS AGEingress-nginx pod/nginx-ingress-controller-8zp8r 1 2d3hingress-nginx pod/nginx-ingress 1 Running 0 2d3hingress-nginx pod/nginx-ingress-controller-bfgj6 1 Running 0 2d3hingress-nginx pod/nginx-ingress -controller-n5k22 1 + 1 Running 0 2d3hkube-system pod/coredns-59fb8d54d6-n6m5w 1 + + 1 Running 0 2d3hkube-system pod/kube-flannel-ds-amd64-jwvw6 1 + + 1 Running 0 2d3hkube-system pod/kube-flannel-ds-amd64-m92sg 1/1 Running 0 2d3hkube-system pod/kube-flannel-ds-amd64-xwf2h 1/1 Running 0 2d3hkubernetes-dashboard pod/dashboard-metrics-scraper-566cddb686-smw6p 1/1 Running 0 2d3hkubernetes-dashboard pod/kubernetes-dashboard-c4bc5bd44-zgd82 1/1 Running 0 2d3hNAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEdefault service/kubernetes ClusterIP 10.0.0.1 443/TCP 2d3hingress-nginx service/ingress-nginx ClusterIP 10.0.0.22 80/TCP 443/TCP 2d3hkube-system service/kube-dns ClusterIP 10.0.0.2 53/UDP,53/TCP 2d3hkubernetes-dashboard service/dashboard-metrics-scraper ClusterIP 10.0.0.176 8000/TCP 2d3hkubernetes-dashboard service/kubernetes-dashboard NodePort 10.0.0.72 443:30001/TCP 2d3h
Deploy multiple master effects
[root@k8s-master1 ~] # kubectl get nodeNAME STATUS ROLES AGE VERSIONk8s-master1 Ready 6m18s v1.16.0k8s-master2 Ready 6m17s v1.16.0k8s-node1 Ready 6m10s v1.16.0k8s-node2 Ready 6m16s v1.16.0 [root@k8s-master1 ~] # kubectl get csNAME AGEcontroller-manager scheduler etcd-2 Etcd-1 etcd-0 [root@k8s-master1 ~] # kubectl get pod Svc-ANAMESPACE NAME READY STATUS RESTARTS AGEingress-nginx pod/nginx-ingress-controller-4nf6j 1 45singress-nginx pod/nginx-ingress 1 Running 0 45singress-nginx pod/nginx-ingress-controller-5fknt 1 Running 0 45singress-nginx pod/nginx-ingress -controller-lwbkz 1 to 1 Running 0 45singress-nginx pod/nginx-ingress-controller-v8k8n 1 to 1 Running 0 45skube-system pod/coredns-59fb8d54d6-959xj 1 to 1 Running 0 6m44skube-system pod/kube-flannel-ds-amd64-2hnzq 1/1 Running 0 6m31skube-system pod/kube-flannel-ds-amd64- 64hqc 1/1 Running 0 6m25skube-system pod/kube-flannel-ds-amd64-p9d8w 1/1 Running 0 6m32skube-system pod/kube-flannel-ds-amd64-pchp5 1 / 1 Running 0 6m33skubernetes-dashboard pod/dashboard-metrics-scraper-566cddb686-kf4qq 1 AGEdefault 1 Running 0 32skubernetes-dashboard pod/kubernetes-dashboard-c4bc5bd44-dqfb8 1 Running 0 32sNAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEdefault Service/kubernetes ClusterIP 10.0.0.1 443/TCP 19mingress-nginx service/ingress-nginx ClusterIP 10.0.0.53 80/TCP 443/TCP 45skube-system service/kube-dns ClusterIP 10.0.0.2 53/UDP,53/TCP 6m47skubernetes-dashboard service/dashboard-metrics-scraper ClusterIP 10.0.0.147 8000/TCP 32skubernetes-dashboard service/kubernetes-dashboard NodePort 10.0.0.176 443:30001/TCP 32s
Expand Node node
Simulate the expansion of node nodes. Because I have too many resources, I cannot allocate them, resulting in the status of pending.
[root@k8s-master1] # kubectl run web-image=nginx-replicas=6-requests= "cpu=1 Memory=256Mi "[root@k8s-master1 ~] # kubectl get podNAME READY STATUS RESTARTS AGEweb-944cddf48-6qhcl 1 7ldsv 1 Running 0 15mwebcolor 944cddf48-7ldsv 1 Running 0 15mwebwash944cddf48-7nv9p 0qqr 1 Pending 0 2sweb-944cddf48-b299n 1lap 1 Running 0cddf48-1 Pending 0 15mweb- 944cddf48-pl4zt 1/1 Running 0 15mweb-944cddf48-t8fqt 1/1 Running 0 15m
The current state is that pod cannot allocate resources to the current node due to insufficient resource pool, so now we need to expand our node node.
Execute playbook to specify a new node
[root@ansible ansible-install-k8s-master] # ansible-playbook-I hosts add-node.yml-uroot-k
Check that the request to join node has been received, and run through the
[root@k8s-master1 ~] # kubectl get csrNAME AGE REQUESTOR CONDITIONnode-csr-0i7BzFaf8NyG_cdx_hqDmWg8nd4FHQOqIxKa45x3BJU 45m kubelet-bootstrap Approved,Issued
View node node status
[root@k8s-master1 ~] # kubectl get nodeNAME STATUS ROLES AGE VERSIONk8s-master1 Ready 7d v1.16.0k8s-node1 Ready 7d v1.16.0k8s-node2 Ready 7d v1.16.0k8s-node3 Ready 2m52s v1.16.0
Check that pod resources have been automatically assigned to the new node
[root@k8s-master1] # kubectl get podNAME READY STATUS RESTARTS AGEweb-944cddf48-6qhcl 1According 1 Running 0 80m webmer944cddf48-7ldsv 1According to 1 Running 080mwebmerry 944cddf48-7nv9p 1xxx 1 Running 0 65mweb-944cddf48-b299n 1According to 1 Running 0 80mweb-944cddf48-nsxgg 1According to 1 Running 080m webmer944cddf48- Pl4zt 1/1 Running 0 80mweb-944cddf48-t8fqt 1/1 Running 0 80m
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.