kubeadmin安装部署k8s
一、系统配置(所有节点都需要执行)关闭防火墙systemctl stop firewalldsystemctl disable firewalld禁用SELinuxsetenforce 0编辑文件/etc/selinux/config,将SELINUX修改为disabled,如下:SELINUX=disabled3. 关闭系统Swapswapoff -a系统参数配置cat <<EOF
一、系统配置(所有节点都需要执行)
-
关闭防火墙
systemctl stop firewalld systemctl disable firewalld
-
禁用SELinux
setenforce 0
编辑文件/etc/selinux/config,将SELINUX修改为disabled,如下:
SELINUX=disabled
3. 关闭系统Swap
swapoff -a
-
系统参数配置
cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system
二、安装Docker
cat > /etc/yum.repos.d/docker-ce.repo <<-EOF
[docker-ce-stable]
name=Docker CE Stable Mirror Repository
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
EOF
yum install --enablerepo=docker-ce-stable -y docker-ce-18.06.1.ce
配置加速器
cat > /etc/docker/daemon.json <<-EOF
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"https://registry.cn-hangzhou.aliyuncs.com"
],
"exec-opts": [
"native.cgroupdriver=systemd"
]
}
EOF
systemctl enable docker
systemctl start docker
三、安装Kubernetes组件
-
安装kubectl,kubeadm,kubelet(master节点上执行)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/Centos-7.repo cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 EOF yum clean all yum makecache
查看可用的版本并安装
yum list --showduplicates | grep 'kubeadm\|kubectl\|kubelet'
yum install kubeadm-1.15.0 kubectl-1.15.0 kubelet-1.15.0 --disableexcludes=kubernetes
systemctl enable --now kubelet
备注:此处启动kubelet后会启动失败,因为缺少相关的配置,后续初始化后会自动生成
-
初始化Master节点(master节点上执行)
执行如下命令进行初始化kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=172.17.0.0/16 --kubernetes-version=v1.15.0
–image-repository 初始化过程中需要拉取一些镜像,可用使用ali的镜像仓库,也可以提前将镜像下载下来
–pod-network-cidr 指定 Pod 网络的范围。Kubernetes 支持多种网络方案,而且不同网络方案对 --pod-network-cidr 有自己的要求
–kubernetes-version 版本号
初始化成功后会有如下信息(截取部分)
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 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/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 172.16.9.201:6443 --token mjcpfv.ygwck7pjyue68fw9 --discovery-token-ca-cert-hash sha256:6c31a69d3bfa45a5dd50de2e07f1c71731d17244a009742a3dbf83e03a5a62f6
-
加入node节点(node节点上执行)
使用最后的kubeadm可以用来在其他Node节点上执行,以将其他节点加入到集群中,在接下来的章节会用到。 -
配置kubectl认证信息
非root用户mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config root用户 echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile source ~/.bash_profile
-
安装flannel网络
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
查看Pod信息
kubectl --namespace=kube-system get pod
- 查看集群信息
[root@k8s-node1 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-node1 Ready master 157m v1.15.0
k8s-node2 Ready 152m v1.15.0
k8s-node3 Ready 152m v1.15.0
[root@k8s-node1 ~]#
[root@k8s-node1 ~]# kubectl get cs
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {“health”:“true”}
更多推荐
所有评论(0)