Centos7經過kubeadm部署k8s

機器準備node

192.168.71.60 master
192.168.71.61 node1linux

關閉防火牆(兩臺機器都作)nginx

systemctl stop firewalld
setenforce 0

更改主機名(兩臺機器都作)git

hostnamectl set-hostname  master
bash #直接生效

關閉swap(兩臺機器都作)github

swapoff -a  # 臨時
# vim /etc/fstab  # 永久

設置host(兩臺機器都作)docker

cat <<EOF >>/etc/hosts

192.168.71.60 master
192.168.71.61 node1
192.168.71.62 node2

EOF

更改源(兩臺機器都作)vim

cd /etc/yum.repos.d/
rm -f *
curl -o CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum clean all  
yum makecache  
yum repolist

安裝docker(兩臺機器都作)centos

查看docker可安裝的版本可用yum list docker-ce --showduplicates|grep "^doc"|sort -rapi

yum install -y docker-ce
systemctl enable docker && systemctl start docker  #設置docker開機啓動

安裝kubelet、kubeadm、kubectl、kubernetes-cni(兩臺機器都作)bash

yum install -y kubeadm
systemctl enable kubelet.service

初始化kubeadm(只在master機器執行)

kubeadm init --pod-network-cidr=10.244.0.0/16  --apiserver-advertise-address=192.168.71.60 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.1.0.0/16

根據提示執行下面語句(只在master機器執行)

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

安裝flannel網絡插件(兩臺機器都作)

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

查看pod

kubectl get pods -n kube-system

將node1加入集羣,token要根據上面安裝完的提示(在node1上操做)

kubeadm join 192.168.71.60:6443 --token y58e7a.c938uwuaz1fbeeys \
    --discovery-token-ca-cert-hash sha256:fc18a5172423e70b915158ea34a2101284b3ee98c86cba79bcafadb691f75942

測試集羣(在master上操做)

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-servic

安裝dashboard(在master上操做)

wget https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml
vi kubernetes-dashboard.yaml

將其中的image鏡像地址改爲registry.aliyuncs.com/google_containers
在service中添加type: NodePort,而後

kubectl apply -f kubernetes-dashboard.yaml

kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl get secret -n kube-system

找到帶有dashboard-admin-token...的

kubectl describe secret dashboard-admin-token-pbnnk -n kube-system 獲得admin的token,而後在網頁登陸dashborad

相關文章
相關標籤/搜索