使用kubeadm部署k8s集群
使用kubeadm部署k8s集群停止防火墙systemctl stop firewalldsystemctl disable firewalld关闭senlinuxsetenforce 0vi /etc/selinux/configSELINUX=disabled关闭swapswapoff -avi /etc/fstab注释这句话 #/dev/mapper/centos-swap swapswap
·
使用kubeadm部署k8s集群
- 停止防火墙
systemctl stop firewalld
systemctl disable firewalld
- 关闭senlinux
setenforce 0
vi /etc/selinux/config SELINUX=disabled
- 关闭swap
swapoff -a
vi /etc/fstab 注释这句话 #/dev/mapper/centos-swap swap swap defaults 0 0
- iptables配置修改
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness = 0
EOF
- 查看
sysctl --system
- 开启ipvs
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
yum install -y ipset ipvsadm
- ssh
ssh-keygen
cat /root/.ssh/id_rsa.pub
拷贝到其他master
vi .ssh/authorized_keys
- 安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce docker-ce-cli containerd.io
cat <<EOF>> /etc/docker/daemon.json
{
"insecure-registry":[
"hub.hipstershop.cn",
"reg.hipstershop.cn"
],
"registry-mirrir":"阿里云加速地址",
"graph":"/data1/docker"
}
EOF
- k8s阿里源
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=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
- 安装k8s
yum install kubelet kubeadm kubectl
- 启动服务
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet
- 修改docker配置(需与 k8s统一)
vi /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl restart docker
以上在所有节点执行
master节点初始化
- kubeadm-config.yaml
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
---
apiVersion: kubeadm.k8s.io.v1beta1
apiServer:
certSANs:
- "节点ip"
extraAras:
allow-privileged: "true"
feature-gates: "VolumeSnapshotDataSource=true,CSINodeInfo=true,CSIDriverRegistry=true"
controlPlaneEndpoint: "apiserver.hipstershop.cn:6443"
etcd:
local:
dataDir: /data1/etcd
networking:
# this CIDR is a Canal default
podSubnet: "10.244.0.0/16"
controllerManager:
extraArgs:
address: 0.0.0.0
scheduler:
extraArgs:
address: 0.0.0.0
imageRepository: gcr.azk8s.cn/google-containers
kubeadm init --pod-network-cidr=192.168.0.0/16
- 查看需要哪些镜像
kubeadm config images list
journalctl -f -u kubelet.service
- 提前下载镜像
gcr.azk8s.cn/google-containers
docker pull coredns/coredns:1.3.1
docker pull mirrorgooglecontainers/etcd:3.3.10
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/kube-apiserver:v1.14.2
docker pull mirrorgooglecontainers/kube-controller-manager:v1.14.2
docker pull mirrorgooglecontainers/kube-proxy:v1.14.2
docker tag mirrorgooglecontainers/kube-proxy:v1.14.2 k8s.gcr.io/kube-proxy:v1.14.2
docker tag mirrorgooglecontainers/kube-scheduler:v1.14.2 k8s.gcr.io/kube-scheduler:v1.14.2
docker tag mirrorgooglecontainers/kube-controller-manager:v1.14.2 k8s.gcr.io/kube-controller-manager:v1.14.2
docker tag mirrorgooglecontainers/kube-apiserver:v1.14.2 k8s.gcr.io/kube-apiserver:v1.14.2
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
- calico安装
kubectl apply -f https://docs.projectcalico.org/v3.7/manifests/calico.yaml
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
- master加入
kubectl taint nodes --all node-role.kubernetes.io/master-
- root用户
vi ~/.bashrc
export KUBECONFIG=/etc/kubernetes/admin.conf
- 其他用户
cp -f /etc/kubernetes/admin.conf $HOME/
chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf
echo "export KUBECONFIG=$HOME/admin.conf" >> ~/.bash_profile
- node节点加入
kubeadm join 10.10.32.65:6443 --token 89l78n.4pltegaexxipyfoi \
--discovery-token-ca-cert-hash sha256:87634fbee2666ae00256379deece3e486347b54a32e1528050f8a958fa264f64
USER=root
CONTROL_PLANE_IPS=""
for host in ${CONTROL_PLANE_IPS}; do
scp /etc/kubernetes/pki/ca.crt "${USER}"@$host:
scp /etc/kubernetes/pki/ca.key "${USER}"@$host:
scp /etc/kubernetes/pki/sa.key "${USER}"@$host:
scp /etc/kubernetes/pki/sa.pub "${USER}"@$host:
scp /etc/kubernetes/pki/front-proxy-ca.crt "${USER}"@$host:
scp /etc/kubernetes/pki/front-proxy-ca.key "${USER}"@$host:
scp /etc/kubernetes/etcd/ca.crt "${USER}"@$host:
scp /etc/kubernetes/etcd/ca.key "${USER}"@$host:
scp /etc/kubernetes/admin.conf "${USER}"@$host:
done
更多推荐
已为社区贡献2条内容
所有评论(0)