一、环境准备

1.1 规划

1. 操作系统 CentOS-7.x-x86_64。

2. 关闭 iptables 和 SELinux。

3. 所有节点的主机名和 IP 地址,使用/etc/hosts 做好主机名解析。

主机名 IP地址(NAT) CPU 内存
k8s-master eth0 : 10.0.0.25 1VCPU 2G
k8s-node-1 eth0 : 10.0.0.26 1VCPU 2G
k8s-node-1 eth0 : 10.0.0.27 1VCPU 2G

1.2 网络设置

1.3 配置静态IP地址

  1. #将 UUID 和 MAC 地址已经其它配置删除掉,3个节点除了IP和主机名不同其他相同。
    [root@k8s-master ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
  2. TYPE=Ethernet
  3. BOOTPROTO=static
  4. NAME=eth0
  5. DEVICE=eth0
  6. ONBOOT=yes
  7. IPADDR=10.0.0.25
  8. NETMASK=255.255.255.0
  9. GATEWAY=10.0.0.254
  10. DNS=223.5.5.5
  11.  
  12. #重启网络服务
  13. [root@k8s-master ~]# systemctl restart network
  14.  
  15. #设置 DNS 解析
  16. [root@k8s-master ~]# vi /etc/resolv.conf
  17. nameserver 223.5.5.5

1.4 关闭selinux、防火墙

  1. setenforce 0
  2. sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/selinux/config
  3. systemctl disable firewalld.service
  4. systemctl stop firewalld.service
  5. systemctl stop NetworkManager
  6. systemctl disable NetworkManager

1.5 设置主机名解析

3个节点都做

cat >>/etc/hosts<<EOF
10.0.0.25 k8s-master
10.0.0.26 k8s-node-1
10.0.0.27 k8s-node-2
EOF

1.6 配置epel源

3个节点都做

  1. rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
  2. #下载常用命令
  3. yum install -y net-tools vim lrzsz tree screen lsof tcpdump nc mtr nmap
  4.  
  5. #保证能上网
  6. [root@k8s-master ~]# ping www.baidu.com -c3
  7. PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
  8. 64 bytes from 61.135.169.121: icmp_seq=1 ttl=128 time=5.41 ms
  9. 64 bytes from 61.135.169.121: icmp_seq=2 ttl=128 time=6.55 ms
  10. 64 bytes from 61.135.169.121: icmp_seq=3 ttl=128 time=8.97 ms
  11.  
  12. --- www.a.shifen.com ping statistics ---
  13. 3 packets transmitted, 3 received, 0% packet loss, time 2023ms
  14. rtt min/avg/max/mdev = 5.418/6.981/8.974/1.486 ms

1.7 配置免秘钥登录

只在master节点做

  1. [root@k8s-master ~]# ssh-keygen -t rsa
  2. Generating public/private rsa key pair.
  3. Enter file in which to save the key (/root/.ssh/id_rsa):
  4. Enter passphrase (empty for no passphrase):
  5. Enter same passphrase again:
  6. Your identification has been saved in /root/.ssh/id_rsa.
  7. Your public key has been saved in /root/.ssh/id_rsa.pub.
  8. The key fingerprint is:
  9. b1:a0:5b:::0e:8f:1e::bf::1f:d1:f3::c4 root@k8s-master
  10. The key's randomart image is:
  11. +--[ RSA ]----+
  12. | o o .+. |
  13. | X .E . |
  14. | . + * o = |
  15. | + + + + . |
  16. | + + S |
  17. | = |
  18. | . |
  19. | |
  20. | |
  21. +-----------------+
  22. [root@k8s-master ~]# ssh-copy-id k8s-master
  23. The authenticity of host 'k8s-master (10.0.0.25)' can't be established.
  24. ECDSA key fingerprint is :5c::a1:b4:cc:bf:::a5:d5:d1:::3c:9a.
  25. Are you sure you want to continue connecting (yes/no)? yes
  26. /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
  27. /usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
  28. root@k8s-master's password:
  29.  
  30. Number of key(s) added:
  31.  
  32. Now try logging into the machine, with: "ssh 'k8s-master'"
  33. and check to make sure that only the key(s) you wanted were added.
  34.  
  35. [root@k8s-master ~]# ssh-copy-id k8s-node-
  36. The authenticity of host 'k8s-node-1 (10.0.0.26)' can't be established.
  37. ECDSA key fingerprint is :5c::a1:b4:cc:bf:::a5:d5:d1:::3c:9a.
  38. Are you sure you want to continue connecting (yes/no)? yes
  39. /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
  40. /usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
  41. root@k8s-node-'s password:
  42.  
  43. Number of key(s) added:
  44.  
  45. Now try logging into the machine, with: "ssh 'k8s-node-1'"
  46. and check to make sure that only the key(s) you wanted were added.
  47.  
  48. [root@k8s-master ~]# ssh-copy-id k8s-node-
  49. The authenticity of host 'k8s-node-2 (10.0.0.27)' can't be established.
  50. ECDSA key fingerprint is :5c::a1:b4:cc:bf:::a5:d5:d1:::3c:9a.
  51. Are you sure you want to continue connecting (yes/no)? yes
  52. /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
  53. /usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
  54. root@k8s-node-'s password:
  55.  
  56. Number of key(s) added:
  57.  
  58. Now try logging into the machine, with: "ssh 'k8s-node-2'"
  59. and check to make sure that only the key(s) you wanted were added.

二、安装Salt-SSH并克隆本项目代码

2.1master节点做

  1. 2.1 安装Salt SSH
  2. [root@k8s-master ~]# yum install -y https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm
  3. [root@k8s-master ~]# yum install -y salt-ssh git
  4.  
  5. 2.2 获取项目代码放置在/srv目录
  6. [root@k8s-master ~]# git clone https://github.com/unixhot/salt-kubernetes.git
  7. [root@k8s-master ~]# cd salt-kubernetes/
  8. [root@k8s-master salt-kubernetes]# mv * /srv/
  9. [root@k8s-master salt-kubernetes]# cd /srv/
  10. [root@k8s-master srv]# cp master /etc/salt/master
  11. [root@k8s-master srv]# cp roster /etc/salt/roster
  12.  
  13. 2.3 下载二进制文件
  14. 链接: https://pan.baidu.com/s/1kJmvR9wzleHGHnSVHaNpMg
  15. 密码: 4taa
  16. 下载完成后,将文件移动到/srv/salt/k8s/目录下。
  17. [root@linux-node1 ~]# cd /srv/salt/k8s/
  18. [root@k8s-master k8s]# unzip k8s-v1.9.3-auto.zip
  19. [root@k8s-master k8s]# ls -l files/
  20. 总用量
  21. drwxr-xr-x root root 3 : cfssl-1.2
  22. drwxrwxr-x root root 3 : cni-plugins-amd64-v0.7.0
  23. drwxr-xr-x root root 3 : etcd-v3.3.1-linux-amd64
  24. drwxr-xr-x root root 3 : flannel-v0.10.0-linux-amd64
  25. drwxr-xr-x root root 3 : k8s-v1.9.3

三、Salt SSH管理的机器以及角色分配

  • k8s-role: 用来设置K8S的角色
  • etcd-role: 用来设置etcd的角色,如果只需要部署一个etcd,只需要在一台机器上设置即可
  • etcd-name: 如果对一台机器设置了etcd-role就必须设置etcd-name

3.1master节点做

  1. [root@k8s-master ~]# vim /etc/salt/roster
  2. k8s-master:
  3. host: 10.0.0.25
  4. user: root
  5. priv: /root/.ssh/id_rsa
  6. minion_opts:
  7. grains:
  8. k8s-role: master
  9. etcd-role: node
  10. etcd-name: etcd-node1
  11.  
  12. k8s-node-:
  13. host: 10.0.0.26
  14. user: root
  15. priv: /root/.ssh/id_rsa
  16. minion_opts:
  17. grains:
  18. k8s-role: node
  19. etcd-role: node
  20. etcd-name: etcd-node2
  21.  
  22. k8s-node-:
  23. host: 10.0.0.27
  24. user: root
  25. priv: /root/.ssh/id_rsa
  26. minion_opts:
  27. grains:
  28. k8s-role: node
  29. etcd-role: node
  30. etcd-name: etcd-node3

四、配置参数

4.1master节点做

  1. [root@k8s-master ~]# vim /srv/pillar/k8s.sls
  2. # -*- coding: utf- -*-
  3.  
  4. #设置Master的IP地址(必须修改)
  5. MASTER_IP: "10.0.0.25"
  6.  
  7. #设置ETCD集群访问地址(必须修改)
  8. ETCD_ENDPOINTS: "https://10.0.0.25:2379,https://10.0.0.26:2379,https://10.0.0.27:2379"
  9.  
  10. #设置ETCD集群初始化列表(必须修改)
  11. ETCD_CLUSTER: "etcd-node1=https://10.0.0.25:2380,etcd-node2=https://10.0.0.26:2380,etcd-node3=https://10.0.0.27:2380"
  12.  
  13. #通过Grains FQDN自动获取本机IP地址,请注意保证主机名解析到本机IP地址
  14. NODE_IP: {{ grains['fqdn_ip4'][] }}
  15.  
  16. #设置BOOTSTARP的TOKEN,可以自己生成
  17. BOOTSTRAP_TOKEN: "ad6d5bb607a186796d8861557df0d17f"
  18.  
  19. #配置Service IP地址段
  20. SERVICE_CIDR: "10.1.0.0/16"
  21.  
  22. #Kubernetes服务 IP (从 SERVICE_CIDR 中预分配)
  23. CLUSTER_KUBERNETES_SVC_IP: "10.1.0.1"
  24.  
  25. #Kubernetes DNS 服务 IP (从 SERVICE_CIDR 中预分配)
  26. CLUSTER_DNS_SVC_IP: "10.1.0.2"
  27.  
  28. #设置Node Port的端口范围
  29. NODE_PORT_RANGE: "20000-40000"
  30.  
  31. #设置POD的IP地址段
  32. POD_CIDR: "10.2.0.0/16"
  33.  
  34. #设置集群的DNS域名
  35. CLUSTER_DNS_DOMAIN: "cluster.local."

五、执行SaltStack状态

5.1master节点做

  1. 5.1 测试Salt SSH联通性
  2. [root@k8s-master ~]# salt-ssh '*' test.ping
  1. 5.2 部署Etcd,由于Etcd是基础组建,需要先部署,目标为部署etcd的节点。
  2. [root@k8s-master ~]# salt-ssh -L 'k8s-master,k8s-node-1,k8s-node-2' state.sls k8s.etcd

  3. 5.3 部署K8S集群
  4. 由于包比较大,这里执行时间较长,5分钟+,如果执行有失败可以再次执行即可!
  5. [root@k8s-master ~]# salt-ssh '*' state.highstate

六、测试Kubernetes安装

6.1master节点做

  1. [root@k8s-master ~]# source /etc/profile
  2. [root@k8s-master ~]# kubectl get cs
  3. [root@k8s-master ~]# kubectl get node

七、测试Kubernetes集群和Flannel网络

7.1master节点做

  1. [root@k8s-master ~]# kubectl run net-test --image=alpine --replicas= sleep
  2. 需要等待拉取镜像,可能稍有的慢,请等待。
  3. [root@linux-node1 ~]# kubectl get pod -o wide
  4.  
  5. 测试联通性,如果都能ping通,说明Kubernetes集群部署完毕,。
  6. [root@k8s-master ~]# ping -c 10.2.12.2
  7. PING 10.2.12.2 (10.2.12.2) () bytes of data.
  8. bytes from 10.2.12.2: icmp_seq= ttl= time=8.72 ms
  9.  
  10. --- 10.2.12.2 ping statistics ---
  11. packets transmitted, received, % packet loss, time 0ms
  12. rtt min/avg/max/mdev = 8.729/8.729/8.729/0.000 ms
  13.  
  14. [root@k8s-master ~]# ping -c 10.2.24.2
  15. PING 10.2.24.2 (10.2.24.2) () bytes of data.
  16. bytes from 10.2.24.2: icmp_seq= ttl= time=22.9 ms
  17.  
  18. --- 10.2.24.2 ping statistics ---
  19. packets transmitted, received, % packet loss, time 0ms
  20. rtt min/avg/max/mdev = 22.960/22.960/22.960/0.000 ms

八、如何新增Kubernetes节点

  1. . 设置主机名解析
  2.  
  3. . 设置SSH无密码登录
  4.  
  5. . 在/etc/salt/roster里面,增加对应的机器IP
  6.  
  7. . 执行SaltStack状态:salt-ssh '*' state.highstate
  8.  
  9. . [root@k8s-node- ~]# vim /etc/salt/roster
  10. k8s-node-:
  11. host: 10.0.0.28
  12. user: root
  13. priv: /root/.ssh/id_rsa
  14. minion_opts:
  15. grains:
  16. k8s-role: node
  17.  
  18. . [root@linux-node1 ~]# salt-ssh '*' state.highstate

使用saltstack自动部署K8S的更多相关文章

  1. 持续集成之应用k8s自动部署

    持续集成之应用k8s自动部署 Intro 上次我们提到了docker容器化及自动化部署,这仅仅适合个人项目或者开发环境部署,如果要部署到生产环境,必然就需要考虑很多因素,比如访问量大了如何调整部署,如 ...

  2. spinnaker自动发布k8s部署应用<一>

    一.准备环境 !docker-ce---17.06.2-ce !k8s集群----1.11.1 !helm部署工具---helm-v2.10.0 !spinnaker-charts---spinnak ...

  3. 基于saltstack自动化部署高可用kubernetes集群

    SaltStack自动化部署HA-Kubernetes 本项目在GitHub上,会不定期更新,大家也可以提交ISSUE,地址为:https://github.com/skymyyang/salt-k8 ...

  4. 使用saltstack批量部署服务器运行环境事例——批量部署nagios客户端

    之前关于搭建web服务器集群实验的这篇文章http://www.cnblogs.com/cjyfff/p/3553579.html中,关于如何用saltstack批量部署服务器这一点当时没有记录到文章 ...

  5. kubernetes系列03—kubeadm安装部署K8S集群

    本文收录在容器技术学习系列文章总目录 1.kubernetes安装介绍 1.1 K8S架构图 1.2 K8S搭建安装示意图 1.3 安装kubernetes方法 1.3.1 方法1:使用kubeadm ...

  6. 自动化运维工具SaltStack详细部署【转】

    ==========================================================================================一.基础介绍==== ...

  7. 部署 k8s Cluster(上)[转]

    我们将部署三个节点的 Kubernetes Cluster. k8s-master 是 Master,k8s-node1 和 k8s-node2 是 Node. 所有节点的操作系统均为 Ubuntu ...

  8. .Net Core自动化部署系列(三):使用GitLab CI/CD 自动部署Api到Docker

    之前写过使用Jenkins实现自动化部署,最近正好没事研究了下GitLab的自动化部署,顺便记录一下. 使用GitLab部署我们需要准备两件事,第一个起码你得有个GitLab,自己搭建或者使用官方的都 ...

  9. Kubeasz部署K8s基础测试环境简介

    下面介绍使用Kubeasz部署K8s集群环境. https://github.com/easzlab/kubeasz在需要使用kubeeasz项目安装的k8s时,需要将所有需要它来部署的节点上,都安装 ...

随机推荐

  1. GeoServer 安装教程

    准备内容 安装环境:win10*64位专业版 安装文件:geoserver-2.15.2 安装步骤 安装JDK 1.安装GeoServer是基于Java的环境,所以需要先装Jdk环境. 2.前往官网下 ...

  2. linux awk(gawk)

    awk的前世今生: awk名字的由来:分别取三个创始人Ah,Weiberger,Kernighan三个人的首字母. awk是一个报告生成器可以格式化输出文本内容.模式扫描和处理语言(pattern s ...

  3. 搭建nextcloud私有云存储网盘

    简介: 搭建个人云存储一般会想到ownCloud,堪称是自建云存储服务的经典.而Nextcloud是ownCloud原开发团队打造的号称是“下一代”存储. 真正试用过后就由衷地赞同这个Nextclou ...

  4. ThinkPHP多表查询之join方法

    现在的目的是要把article_category中的name字段导入到article中去 表yz_article如下 表yz_article_category如下

  5. webpack4.0(二)--热更新

    webpack4.0---热更新 使用webpack可帮助我们的开发以及打包,在开发过程中,有时候我们只修改了部分代码并想不必刷新整个页面即可看到更改后的效果,这时候 webpack-dev-serv ...

  6. webpack-优化阻塞的css

    随着浏览器的日新月异,网页的性能和速度越来越好,并且对于用户体验来说也越来越重要. 现在有很多优化页面的办法,比如:静态资源的合并和压缩,code splitting,DNS预读取等等. 本文介绍的是 ...

  7. 基于VMware Workstation下CentOS的搭建

    网络安全学习内容 二.VMware安装CentOS系统 需要准备的文件: 从http://mirrors.huaweicloud.com/centos/7.7.1908/isos/x86_64/中下载 ...

  8. 洛谷 3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题解

    本蒟蒻又来发题解了, 一道较水的模拟题. 题意不过多解释, 思路如下: 在最开始的时候求出每头牛在t秒的位置(最终位置 然后,如果后一头牛追上了前一头牛,那就无视它, 把它们看成一个整体. else ...

  9. 定时器注解 @Scheduled 使用

    试列代码: @Component @Slf4j //配置文件注入注解 @PropertySource("classpath:/**.properties") public clas ...

  10. mac eclipse Android开发环境搭建

    http://www.cnblogs.com/macro-cheng/archive/2011/09/30/android-001.html