暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

k8s安装

原创 charles 2022-05-12
481

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo


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



cat>>/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

gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

EOF


yum -y install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git


systemctl disable --now firewalld

systemctl disable --now dnsmasq

systemctl disable --now NetworkManager


swapoff -a && sysctl -w vm.swappiness=0

sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab


ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


echo 'Asia/Shanghai' >/etc/timezone

ntpdate time2.aliyun.com


*/5 * * * * ntpdate time2.aliyun.com


ulimit -SHn 65535



cat>>/etc/security/limits.conf<

* soft nofile 655360

* hard nofile 131072

* soft nproc 655350

* hard nproc 655350

* soft memlock unlimited

* hard memlock unlimited

EOF


每个主机创建

ssh-keygen -t rsa

三个回车


cat id_rsa.pub >>authorized_keys

cat id_rsa.pub >>2

cat id_rsa.pub >>3

id_rsa.pub 写入authorized_keys


cat 2 >>authorized_keys

cat 3 >>authorized_keys


cd /root/ ; git clone https://github.com/dotbalo/k8s-ha-install.git


yum update -y --exclude=kernel* && reboot



rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

# 安装完成后检查 /boot/grub2/grub.cfg 中对应内核 menuentry 中是否包含 initrd16 配置,如果没有,再安装 一次!

yum --enablerepo=elrepo-kernel install -y kernel-lt

# 设置开机从新内核启动

grub2-set-default 'CentOS Linux (4.4.189-1.el7.elrepo.x86_64) 7 (Core)'


yum -y install ipvsadm ipset sysstat conntrack libseccomp



cat>>/etc/modules-load.d/ipvs.conf<

ip_vs

ip_vs_lc

ip_vs_wlc

ip_vs_rr

ip_vs_wrr

ip_vs_lblc

ip_vs_lblcr

ip_vs_dn

ip_vs_sh

ip_vs_fo

ip_vs_nq

ip_vs_sed

ip_vs_ftp

ip_vs_sh

nf_conntrack

ip_tables

ip_set

xt_set

ipt_set

ipt_rpfilter

ipt_REJECT

ipip

EOF



systemctl enable --now systemd-modules-load.service


lsmod | grep -e ip_vs -e nf_conntrrack_ipv4



cat>>/etc/sysctl.d/k8s.conf<

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

net.ipv4.ip_forward=1

fs.may_detach_mounts = 1

vm.overcommit_memory = 1

vm.panic_on_oom = 0

fs.inotify.max_user_watches=89100

fs.file-max=52706963

fs.nr_open=52706963

net.netfilter.nf_conntrack_max=2310720


net.ipv4.tcp_keepalive_time = 600

net.ipv4.tcp_keepalive_probes = 3

net.ipv4.tcp_keepalive_intv1 = 15

net.ipv4.tcp_max_tw_buckets = 36000

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_max_orphans = 327680

net.ipv4.tcp_orphan_retries = 3

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_max_syn_backlog = 16384

net.ipv4.tcp_conntrack_max = 65536

net.ipv4.tcp_syn_backlog = 16384

net.ipv4.tcp_tcp_timestamps = 0

net.core.somaxconn = 16384

net.ipv6.conf.all.disable_ipv6=1

EOF


sh install.sh docker-19.03.14.tgz


cat>>/etc/docker/daemon.json<

{

"registry-mirrors": ["https://amof2c5e.mirror.aliyuncs.com"],

"exec-opts": ["native.cgroupdriver=systemd"],

"log-driver": "json-file",

"log-opts": {

"max-size": "100m"

},

"insecure-registries": ["https://hub.charlesjiang.top"],

"storage-driver": "overlay2",

"storage-opts": [

"overlay2.override_kernel_check=true"

]

}

EOF


systemctl daemon-reload && systemctl enable --now docker && systemctl restart docker


yum remove kubelet kubeadm kubectl

yum install -y kubelet-1.22.3 kubeadm-1.22.3 kubectl-1.22.3

systemctl daemon-reload && systemctl enable --now kubelet


cat>>/etc/sysconfig/kubelet<

KUBELET_EXTRA_ARGS="--cgroup-driver=systemd --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.2"

EOF



kubeadm config print init-defaults

kubeadm config images list --image-repository registry.aliyuncs.com/google_containers //列出所需镜像


# kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers //拉取镜像

kubeadm init --pod-network-cidr=10.244.0.0/16 --image-repository registry.aliyuncs.com/google_containers

kubeadm init --config kubeadm-config.yaml




mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config


export KUBECONFIG=/etc/kubernetes/admin.conf


命令补全

yum -y install bash-completion

source /usr/share/bash-completion/bash_completion


source <(kubectl completion bash)


echo "source <(kubectl completion bash)" >> ~/.bashrc




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


systemctl restart kubelet



安装

kubectl apply -f https://addons.kuboard.cn/kuboard/kuboard-v3.yaml


kubectl get pods -n kuboard

访问 Kuboard

在浏览器中打开链接 http://your-node-ip-address:30080


输入初始用户名和密码,并登录


用户名: admin

密码: Kuboard123

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论