k8s实践Centos7

https://blog.51cto.com/3241766/2405624

一、所有节点安装docker
1)安装docker
wget https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
2)配置docker
配置代理可选
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf <<-‘EOF’
[Service]
Environment=”HTTP_PROXY=http://10.68.4.22:808″
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

3)配置国内镜像加速地址
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF’
{
“registry-mirrors”: [“https://ouw84i2o.mirror.aliyuncs.com”],
“exec-opts”: [“native.cgroupdriver=systemd”]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

二、安装k8s
1)配置yum源下载
cat < /etc/yum.repos.d/kubernetes.repo

[kubernetes]

name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet kubeadm kubectl
2)禁用swap
swapoff -a
sed -i.bak ‘/swap/s/^/#/’ /etc/fstab
3)host
cat >> /etc/hosts << EOF
10.68.5.196 master
10.68.5.194 node1
10.68.5.195 node2
EOF
3)防火墙配置开放相应端口
firewall-cmd –add-port=6443/tcp –zone=public –permanent
firewall-cmd –add-port=10250/tcp –zone=public –permanent
firewall-cmd –reload
4)下载k82镜像

[root@master ~]

# more image.sh

!/bin/bash

url=registry.cn-hangzhou.aliyuncs.com/google_containers
version=v1.16.2
images=(kubeadm config images list --kubernetes-version=$version|awk -F '/' '{print $2}')
for imagename in ${images[@]} ; do
docker pull $url/$imagename
docker tag $url/$imagename k8s.gcr.io/$imagename
docker rmi -f $url/$imagename
done
5)
加载环境变量

[root@master ~]

#
echo “export KUBECONFIG=/etc/kubernetes/admin.conf” >>~/.bash_profile
source .bash_profile

6)安装pod网络
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

xx)初始化master
kubeadm init –apiserver-advertise-address 10.68.5.196 –pod-network-cidr=10.244.0.0/16

Leave a Reply