kubadmin K8s简易安装

https://www.cnblogs.com/superlinux/p/12582009.html

基础准备[ALL]

# 1. 关闭防火墙功能
systemctl stop firewalld
systemctl disable firewalld

# 2.关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config 
setenforce 0

# 3. 关闭swap
swapoff -a
#或将命令加入开机启动
echo "swapoff -a" >>/etc/profile

# 4. 服务器规划 ip和主机名按照实际情况
cat > /etc/hosts << EOF
192.168.26.134 k8smaster1
192.168.26.135 k8snode1
192.168.26.136 k8snode2
EOF

#5. 主机名配置:
 hostnamectl set-hostname  k8smaster1
 bash

#6. 时间同步配置
yum install -y ntpdate
ntpdate time.windows.com
ntpdate ntp.aliyun.com

#开启转发
cat > /etc/sysctl.d/k8s.conf << EOF 
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

# 以上可以全部复制粘贴直接运行,但是主机名配置需要重新修改

安装docker[ALL]

#源添加
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
#安装docker-ce
yum install deltarpm docker-ce -y
# 安装指定版版本 
yum -y install docker-ce-18.09.9-3.el7

#也可以查看版本安装
#yum list docker-ce --showduplicates | sort -r

#启动docker
systemctl start docker

docker镜像加速&更换镜像位置[ALL]

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://v368fx49.mirror.aliyuncs.com"],
  "graph": "/home/docker"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

K8S yum源[ALL]

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
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

安装kubadmin 和kublete[ALL]

yum install -y kubelet-1.17.0 kubeadm-1.17.0 kubectl-1.17.0
systemctl enable kubelet

master部署[master]

kubeadm init \
  --apiserver-advertise-address=210.47.47.11 \
  --image-repository registry.aliyuncs.com/google_containers \
  --kubernetes-version v1.18.0 \
  --service-cidr=10.1.0.0/16 \
  --pod-network-cidr=10.244.0.0/16

##如下为结果
Your Kubernetes control-plane 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 should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.26.134:6443 --token h8ppvi.m3slvdd04yfi69l0 \
    --discovery-token-ca-cert-hash sha256:578d4ccd2514ba5c463f4bec700a70d40efda104019ce57f6e9683cd9ccd85b1

配置 kubctl [master]

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

查看集群和node状态并处理问题

[root@k8smaster1 ~]# kubectl get cs
NAME                 STATUS    MESSAGE             ERROR
scheduler            Healthy   ok
controller-manager   Healthy   ok
etcd-0               Healthy   {"health":"true"}
[root@k8smaster1 ~]# kubectl get nodes
NAME         STATUS     ROLES    AGE     VERSION
k8smaster1   NotReady   master   5m46s   v1.17.0

#kubctl get nodes 一直是noready 
看/var/log/messages 或者journalctl -f -u kubelet
Jan 26 21:54:52 k8smaster1 kubelet[43973]: E0126 21:54:52.699858   43973 kubelet.go:2183] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
Jan 26 21:54:56 k8smaster1 kubelet[43973]: W0126 21:54:56.735289   43973 cni.go:237] Unable to update cni config: no networks found in /etc/cni/net.d
是因为flannel  没装导致,安装flannel 过程比较慢关注flannel的pod状态
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

从机执行[]

kubeadm join 210.47.47.11:6443 --token hl3fx2.dan7m88q0um4z2vi     --discovery-token-ca-cert-hash sha256:08d4139e4a13dfbca62dfac7aca88a80ad96bc464e718324bd4eea2566fee7c4

你可能感兴趣的:(kubadmin K8s简易安装)