Kubernetes-使用kubeadmin安装部署

基础环境说明

CentOS Linux release 7.5.1804 (Core)

一、系统配置(所有节点都需要执行)

1. 关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

2. 禁用SELinux

setenforce 0

# 编辑文件/etc/selinux/config,将SELINUX修改为disabled,如下:
SELINUX=disabled

3. 关闭系统Swap

swapoff -a

4. 系统参数配置

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组件

1. 安装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后会启动失败,因为缺少相关的配置,后续初始化后会自动生成

2. 初始化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

3. 加入node节点(node节点上执行)

使用最后的kubeadm可以用来在其他Node节点上执行,以将其他节点加入到集群中,在接下来的章节会用到。

4. 配置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

5. 安装flannel网络

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

# 查看Pod信息
kubectl --namespace=kube-system get pod

6. 查看集群信息

[root@k8s-node1 ~]# kubectl get node
NAME        STATUS   ROLES    AGE    VERSION
k8s-node1   Ready    master   157m   v1.15.0
k8s-node2   Ready    <none>   152m   v1.15.0
k8s-node3   Ready    <none>   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"}

7. 自动化部署

https://gitee.com/aaronding/k8s_auto_install

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值