基础环境准备
硬件准备
机器配置:2核CUP,8G内存,40G系统盘
系统:Ubuntu 16.04
机器数量:3台(master01 node01 node02)

###修改主机名

###修改配置静态hostname
hostnamectl set-hostname master01
hostnamectl set-hostname node01
hostnamectl set-hostname node02

###修改host表

vi /etc/hosts
# kubernetes
172.16.160.59    master01
172.16.160.58    node01
172.16.160.57    node02

###关闭firewalld/SELinux_Ubuntu默认关闭SELinux

ufw disable

###关闭swap

临时关闭:swapoff -a
永久关闭:注释掉/etc/fstab下的swap一行

###开启参数自动补全

vi /etc/bash.bashrc
取消bash-conmpletion注释
# enable bash conmpletion in interactive shells
ifshopt -oq posix;then
  if [ -f /usr/share/bash-conmpletion/bash_conmpletion ]; then
    . /usr/share/bash-conmpletion/bash_conmpletion
  elif [ -f /etc/bash_conmpletion ]; then
    . /etc/bash_conmpletion
  fi
fi
source /etc/bash.bashrc

###更新apt包索引

apt-get update

###安装软件包以允许apt通过HTTPS使用存储库

apt-get -y install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

###安装阿里源GPG证书或添加Docker的官方GPG密钥

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

###安装add-apt-repository工具

apt-get -y install software-properties-common

###添加稳定的存储库或者阿里云的存储库

###添加稳定存储库
add-apt-repository \
   "deb [arch=adm64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
### 添加阿里云稳定的存储库
sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

###更新apt包索引

apt-get update

###Docker版本

apt-cache madison docker-ce

###安装docker

apt-get -y install docker-ce=5:18.09.3~3-0~ubuntu-xenial docker-ce-cli=5:18.09.3~3-0~ubuntu-xenial containerd.io
docker info

###解决问题:WARNING: NO swap limit support(操作系统下docker不支持内存限制的警告)

在基于RPM的系统上不会发生此警告,该系统默认情况下启用这些功能
vim /etc/default/grub 添加或编辑GRUB_CMDLINE_LINUX行以添加这两个键值对"cgroup_enable=memory swapaccount=1",
最终效果:
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1 net.ifnames=0 vga=792 console=tty0 console=ttyS0,115200n8 noibrs"

###执行命令更新grub并重启机器

update-grub && reboot

### docker 在1.13版本之后,将系统iptables 中的FORWARD 链的默认策略设置为DROP,并为连接到 docker0 网桥的容器添加了ACCEPT规则

临时解决办法:iptables -P FORWARD ACCEPT
永久解决方法:vim /lib/systemd/system/docker.service
在[service]下添加:ExecStartPost=/sbin/iptables -P FORWARD ACCEPT
systemctl daemon-reload && systemctl restart docker.service

###设置daemon.json

cat > /etc/docker/daemon.json <<EOF
{
    "exec-opts": ["native.cgroupdriver=systemd"],
    "log-driver": "json-file",
    "log-opts": {
      "max-size" : "100m"
    },
    "storage-driver": "overlay2"
}
EOF
systemctl daemon-reload && systemctl restart docker.service

### 配置apt库

apt-get update && sudo apt-get install -y apt-transport-https curl

###国内源或官方源

curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb http://apt-kubernetes.io/ kubernetes-xenial main
EOF

###更新apt包索引

###安装kubeadm,kubelet,kubectl

apt-get update
apt-get install -y kubelet kubeadm kubectl

###初始化集群

kubeadm init \
--apiserver-advertise-address=172.16.160.59

###配置Kubernetes网络

kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/calico.yaml
或者
kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/canal.yaml

PS:国内pull不下来官方镜像,可以从国内pull镜像下来

注意:新版本的coredns改名了,变成了coredns/coredns,记得在images里面改一下

# 将对应的包, 从国内镜像上拉下来
for  i  in  `kubeadm config images list`;  do
    imageName=${i#k8s.gcr.io/}
    docker pull registry.aliyuncs.com/google_containers/$imageName
    docker tag registry.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
    docker rmi registry.aliyuncs.com/google_containers/$imageName
done;
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐