k8s又推出了一些新的版本,部署的难度又增加了不少,虽然前面做过一些工作:https://blog.csdn.net/yalishadaa/article/details/78765031,但对新版本的k8s安装,基本没有什么太大的帮助,下面我将通过RKE这款开源的安装程序来对k8s进行安装和部署。
rke安装机 centos7.4 192.168.61.140
node1 centos7.4 192.168.61.136
node2 centos7.4 192.168.61.141
rke版本:V0.1.5下载地址
Docker版本:
cd /etc/yum.repos.d
备份旧的配置文件:mv CentOS-Base.repo CentOS-Base.repo.bak
下载阿里源的文件: wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
清理缓存
yum clean all
重新生成缓存
yum makecache
略..(这里只给出相关的配置)
打开/etc/default/docker,修改
/etc/systemd/system/multi-user.target.wants/docker.service目录下的文件,添加镜像(每一个不同版本的docker配置方式不一样,具体的参考官方文档):
打开cd /etc/sysconfig/network-scripts,并做好备份:
cp ifcfg-ens33 ifcfg-ens33_copy
编辑ifcfg-ens33文件,添加下面的配置:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.61.136
NETMASK=255.255.255.0
NM_CONTROLLED=no
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=c9d6d89f-7106-4fa3-a0c1-55b6ba1e8c4e
DEVICE=ens33
ONBOOT=yes
重启网络,使得配置生效:
systemctl restart network.service
vi /etc/hostname
正确的方式是开放集群主机节点之间的6443、2379、2380端口。
修改配置文件/etc/sysconfig/selinux,设置SELINUX=disabled
编辑配置文件/etc/sysctl.conf
sudo vi /etc/sysctl.conf
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
sudo vi /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
使得/etc/sysctl.conf 更改生效:
sudo sysctl -p /etc/sysctl.conf
编辑/etc/hosts文件,
vi /etc/hosts
注释掉下面的这一行:
#::1 localhost ip6-localhost ip6-loopback
关闭防火墙:
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
修改/etc/fstab,注释掉swap项。
启用Cgroup:
修改配置文件/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1"
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
执行sudo update-grub 更新grub
ssh-keygen
ssh-copy-id [email protected] #将公钥分发给136机器
ssh-copy-id [email protected] #将公钥分发给141机器
至此,机器的配置完毕。
编写配置文件,下面是我的配置文件:
---
auth:
strategy: x509
options:
foo: bar
network:
plugin: flannel
options:
flannel_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/flannel
flannel_cni_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/flannel-cni
nodes:
- address: 192.168.61.136
user: a
role: [controlplane, etcd]
ssh_key_path: /home/a/.ssh/id_rsa
- address: 192.168.61.141
user: a
role: [worker]
ssh_key_path: /home/a/.ssh/id_rsa
services:
etcd:
image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/etcd:latest
kube-api:
image: rancher/k8s:v1.8.3-rancher2
service_cluster_ip_range: 10.233.0.0/18
pod_security_policy: false
extra_args:
v: 4
kube-controller:
image: rancher/k8s:v1.8.3-rancher2
cluster_cidr: 10.233.64.0/18
service_cluster_ip_range: 10.233.0.0/18
scheduler:
image: rancher/k8s:v1.8.3-rancher2
kubelet:
image: rancher/k8s:v1.8.3-rancher2
cluster_domain: cluster.local
cluster_dns_server: 10.233.0.3
infra_container_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/pause-amd64:3.0
command: --fail-swap-on=false
kubeproxy:
image: rancher/k8s:v1.8.3-rancher2
system_images:
alpine: alpine:latest
nginx_proxy: rancher/rke-nginx-proxy:0.1.0
cert_downloader: rancher/rke-cert-deployer:0.1.0
kubedns_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-kube-dns-amd64:1.14.5
dnsmasq_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-dnsmasq-nanny-amd64:1.14.5
kubedns_sidecar_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-sidecar-amd64:1.14.5
kubedns_autoscaler_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/cluster-proportional-autoscaler-amd64:1.0.0
# all addon manifests MUST specify a namespace
addons: |-
---
apiVersion: v1
kind: Pod
metadata:
name: my-nginx
namespace: default
spec:
containers:
- name: my-nginx
image: nginx
ports:
- containerPort: 80
执行:./rke up
wget https://dl.k8s.io/v1.8.7/kubernetes-client-linux-amd64.tar.gz
tar -xzvf kubernetes-client-linux-amd64.tar.gz
cp kubernetes/client/bin/kube* /usr/local/bin/
chmod a+x /usr/local/bin/kube*
export PATH=/usr/local/bin:$PATH
mkdir /root/.kube/
cp kube_config_cluster.yml /root/.kube/config
部署完毕。