CentOS7.4安装K8S V1.9.7
环境说明:54.213.227.193 master-1 master34.209.148.163 node-1 slave34.219.106.55 node-2 slave一.master、node节点操作:1.修改etc/hosts文件以及hostnameecho '54.213.227.193 master-134.209.148.163 node-134.219.
54.213.227.193 master-1 master
34.209.148.163 node-1 slave
34.219.106.55 node-2 slave
一.master、node节点操作:
1.修改etc/hosts文件以及hostname
echo '54.213.227.193 master-1
34.209.148.163 node-1
34.219.106.55 node-2' >> /etc/hosts
sudo hostnamectl set-hostname master-1
sudo hostnamectl set-hostname node-1
sudo hostnamectl set-hostname node-2
2.关闭SELinux 需要重启机器, 重启后输入sestatus查看SELinux的状态
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
3.关闭swap分区
swapoff -a
vi /etc/fstab 注释掉swap的那一行
4.关闭系统防火墙
systemctl stop firewalld && systemctl disable firewalld
执行查看防火墙 firewall-cmd --state
5.时间同步
yum -y install ntp
ntptime
timedatectl
systemctl enable ntpd
systemctl restart ntpd.service
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
6.预装安装需要的软件包并安装docker
yum install -y wget git tar xz unzip curl ipset bind-utils
yum -y install docker
启动docker,并设置开机启动
[root@master-1 ~]# systemctl enable docker && systemctl start docker
配置系统路由参数,防止kubeadm报路由警告
echo "
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
" >> /etc/sysctl.conf
sysctl -p
二.CentOS7上安装k8s v1.9.7:
1.先在本地配置k8s yum源
cat > /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
EOF
2.查看本地yum k8s是否有1.9.7的版本:
yum list kubeadm --showduplicates
3.yum安装kubectl kubeadm kubelet 1.9.7的版本:
yum install -y kubelet-1.9.7-0 kubeadm-1.9.7-0 kubectl-1.9.7-0
4.新建docker-pull-images.sh文件,
vi docker-pull-images.sh 加入以下内容
#!/bin/bash
docker pull gcr.io/google_containers/kube-proxy-amd64:v1.9.7
docker pull gcr.io/google_containers/kube-controller-manager-amd64:v1.9.7
docker pull gcr.io/google_containers/kube-apiserver-amd64:v1.9.7
docker pull gcr.io/google_containers/kube-scheduler-amd64:v1.9.7
docker pull gcr.io/google_containers/kubernetes-dashboard-amd64:v1.8.3
docker pull quay.io/coreos/flannel:v0.10.0-amd64
docker pull gcr.io/google_containers/etcd-amd64:3.1.11
docker pull gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.7
docker pull gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.7
docker pull gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.7
docker pull gcr.io/google_containers/pause-amd64:3.0
执行docker-pull-images.sh,加载k8s V1.9.7的镜像
三、master 节点操作
1、启动kubelet
[root@master-1 ~]# systemctl restart kubelet && systemctl enable kubelet
初始化master节点
kubeadm init --kubernetes-version=v1.9.7 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=54.213.227.193
当出现以下内容则说明kubeadm初始化成功.
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You can now join any number of machines by running the following on each node
as root:
kubeadm join --token a16e71.ad7204ef1ca18bbe 54.213.227.193:6443 --discovery-token-ca-cert-hash sha256:aed5623e5082759e1df3569bc14deaf55e80d77200492809ce2cd9b77fb2ad70
备注:kubeadm join xxxx 可以保留下来,如果忘记了,可以通过kubeadm token list 获取
2、按照上面提示,此时还不能用kubectl 控制集群。需要配置环境变量
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
3、kubectl version测试
[root@master-1 k8s_images]# kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.7", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.7", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T20:55:30Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
4、下载flannel
wget https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
[root@master-1 k8s_images]# kubectl create -f kube-flannel.yml
5、查看所pod状态,已经都running
[root@master-1 k8s_images]# kubectl get pod --all-namespaces
四、Node节点操作
1、使用刚刚在master上kubeadm init成功后的kubeadm join –xxx 语句
kubeadm join --token a16e71.ad7204ef1ca18bbe 54.213.227.193:6443 --discovery-token-ca-cert-hash sha256:aed5623e5082759e1df3569bc14deaf55e80d77200492809ce2cd9b77fb2ad70
五、查询集群状态:
wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
在master节点部署kubernetes-dashboard,直接使用离线包里面的kubernetes-dashboard.yaml
[root@master-1 k8s_images]# kubectl create -f kubernetes-dashboard.yaml
[root@master-1 k8s_images]# kubectl get pod --all-namespaces
master上check一下
[root@master-1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master-1 Ready master 1h v1.9.0
node-1 Ready <none> 1h v1.9.0
node-2 Ready <none> 1h v1.9.0
更多推荐
所有评论(0)