K8s centos7安装
K8s centos7安装
参考(https://www.bilibili.com/video/BV1w4411y7Go?p=3&spm_id_from=pageDriver)
本次安装总共三台,一个软路由用来science上网,一个harbor仓库
PS: 以下网络都选为仅主机模式
k8s-master-01 | ![]()
|
||
k8s-node-01 | ![]()
|
||
k8s-node-02 | ![]()
|
||
harbor | ![]()
|
||
软路由 | ![]()
|
||
1.1 软路由安装
PS: 修改镜像源
PS: 执行完这步关机
PS: 调整成1G 内存,1核心
PS: 新增网络适配器(网卡)。
PS: 下图对原理进行讲解,hostnet代表主机,通过nat模式可以与主机相连,koolshare仅主机模式和3台k8s相连接
PS: 重启koolshare
PS: 修改网络ipv4配置
1、安装 k8s 的节点必须是大于 1 核心的 CPU
2、安装节点的网络信息 192.168.66.0/24 10 20 21 100
3、koolshare 软路由的默认密码是 koolshare
PS:内网关闭桥接,谁知ipv4为66
1.2 Master安装
PS: 设置root密码,分别安装node1、node2
2、安装节点的网络信息 192.168.66.0/24 10(master) 20(node1) 21(node2) 100
IPADDR=192.168.66.20
NETMASK=255.255.255.0
GATEWAY=192.168.66.1
DNS1=192.168.66.1
DNS2=114.114.114.114
vi /etc/sysconfig/network-scripts/ifcfg-ens33
PS: 执行完 重启网络systemctl restart network
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=9f6fd801-9872-4b69-afb5-53ff23a515f5
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.88.30
NETMASK=255.255.255.0
GATEWAY=192.168.88.2
DNS1=8.8.8.8
DNS2=114.114.114.114
PS: 配置远程连接
hostnamectl set-hostname k8s-master01
hostnamectl set-hostname k8s-node01
hostnamectl set-hostname k8s-node02
192.168.88.50 k8s-master01
192.168.88.51 k8s-node01
192.168.88.52 k8s-node02
192.168.88.100 hub.atguigu.com
scp /etc/hosts root@k8s-node02:/etc/hosts
PS:设置系统主机名和host文件相互解析
yum install -y conntrack ntpdate ntp ipset jq iptables curl sysstat libseccomp wget vim net-tools git
PS: 安装依赖包,每台都要执行
1、 systemctl stop firewalld && systemctl disable firewalld
2、
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
PS: 关闭防火墙,设置iptables为空规则 每台都要执行
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
关闭虚拟内存,因为有可能k8s启动起来,就会在虚拟内存运行起来,所以关闭;
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
PS: 关闭 SELINUX
cat > kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它
vm.overcommit_memory=1 # 不检查物理内存是否够用
vm.panic_on_oom=0 # 开启 OOM
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF
拷贝文件到指定位置,开机启动
cp kubernetes.conf /etc/sysctl.d/kubernetes.conf
让文件生效
sysctl -p /etc/sysctl.d/kubernetes.conf
文件不存在先不管他
PS: 调整内核参数,对于 K8S
调整系统时区
# 设置系统时区为 中国/上海
timedatectl set-timezone Asia/Shanghai
# 将当前的 UTC 时间写入硬件时钟
timedatectl set-local-rtc 0
# 重启依赖于系统时间的服务
systemctl restart rsyslog
systemctl restart crond
关闭系统不需要服务
systemctl stop postfix && systemctl disable postfix
设置 rsyslogd 和 systemd journald
mkdir /var/log/journal # 持久化保存日志的目录
mkdir /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/99-prophet.conf <<EOF
[Journal]
# 持久化保存到磁盘
Storage=persistent
# 压缩历史日志
Compress=yes
SyncIntervalSec=5m
RateLimitInterval=30s
RateLimitBurst=1000
# 最大占用空间 10G
SystemMaxUse=10G
# 单日志文件最大 200M
SystemMaxFileSize=200M
# 日志保存时间 2 周
MaxRetentionSec=2week
# 不将日志转发到 syslog
ForwardToSyslog=no
EOF
systemctl restart systemd-journald
PS: 升级系统内核为 4.44
CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs,导致运行的 Docker、Kubernetes 不稳定,例如: rpm -Uvh
http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
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)'
设置完重新启动
reboot
uname -r 查看内核版本
我的系统版本会最新的
kube-proxy开启ipvs的前置条件(此步骤替换为 https://blog.csdn.net/weixin_45387943/article/details/123225090)
modprobe br_netfilter
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack
安装 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 update -y && yum install -y docker-ce
安装完重启服务器
grub2-set-default 'CentOS Linux (5.4.211-1.el7.elrepo.x86_64) 7 (Core)' && reboot
systemctl start docker && systemctl enable docker
## 创建 /etc/docker 目录
mkdir /etc/docker
# 配置 daemon.
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": [
"native.cgroupdriver=systemd"
],
"insecure-registries": [
"https://hub.atguigu.com"
],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
}
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
# 重启docker服务
systemctl daemon-reload && systemctl restart docker && systemctl enable docker
安装 Kubeadm (主从配置)
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum -y install kubeadm-1.15.1 kubectl-1.15.1 kubelet-1.15.1
systemctl enable kubelet.service
tar -zxvf ssss
PS: 上传基础镜像
docker load < apiserver.tar
docker load < coredns.tar
docker load < etcd.tar
docker load < kubec-con-man.tar
docker load < pause.tar
docker load < proxy.tar
docker load < scheduler.tar
初始化主节点
kubeadm config print init-defaults > kubeadm-config.yaml
localAPIEndpoint:
advertiseAddress: 192.168.66.10
kubernetesVersion: v1.15.1
networking:
podSubnet: "10.244.0.0/16"
serviceSubnet: 10.96.0.0/12
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
SupportIPVSProxyMode: true
mode: ipvs
kubeadm init --config=kubeadm-config.yaml --experimental-upload-certs | tee kubeadm-init.log
PS:安装docker的时候,不要安装最新版本
https://blog.csdn.net/qq_42910468/article/details/126037954
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
PS: 因为网络扁平化的原因,他没有启动,需要操作配置 flannel
加入主节点以及其余工作节点
执行安装日志中的加入命令即可
部署网络
mv kubeadm-init.log kubeadm-config.yaml install-k8s/
cd /root/install-k8s/flannel
这个文件目前是不可以使用了
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl -n kube-system get pod
加入其他字节点
kubeadm-basic.images]# kubeadm join 192.168.66.10:6443 --token abcdef.0123456789abcdef \
> --discovery-token-ca-cert-hash sha256:74603f5dd8d31b589791ceeb641f8cbae85f0d5e4244640534b0534885f16487
kubectl get pod -n kube-system
PS: 查看网络的启动状态
启动完成!!!
子节点启动不到信息。
https://blog.csdn.net/zhengzaifeidelushang/article/details/123674589
Harbor安装
1、安装docer
yum -y install lrzsz
mv docker-compose /usr/local/bin/
[root@localhost ~]# chmod a+x /usr/local/bin/docker-compose
[root@localhost ~]# docker-compose -v
docker-compose version 1.23.1, build b02f1306
tar -zxvf harbor-offline-installer-v1.2.0.tgz
mv harbor /usr/local/
PS: 修改配置文件
![](https://img2022.cnblogs.com/blog/1068610/202205/1068610-20220512183911440-634845464.png)
![](https://img2022.cnblogs.com/blog/1068610/202205/1068610-20220512184002924-48724592.png)
![](https://img2022.cnblogs.com/blog/1068610/202205/1068610-20220512184022105-1523133036.png)
![](https://img2022.cnblogs.com/blog/1068610/202205/1068610-20220512184149503-1629621635.png)
chmod a+x *
admin / Harbor12345
测试镜像和集群是否是通的,启动失败(参考这个 https://blog.csdn.net/CEVERY/article/details/108753379):
kubectl run deployment --image=hub.atguigu.com/library/nginx:latest --port=80 replicas=1
K8s 安装helm
https://mirrors.huaweicloud.com/helm/v2.13.1/
cp -a linux-amd64/helm /usr/local/bin/
chmod a+x /usr/local/bin/helm
创建 rmac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system
kubectl create -f rbac-config.yaml
helm init --service-account tiller --skip-refresh
kubectl get pods -n kube-system
下载私有镜像,导入
https://helm.sh/ helm官网
Helm 创建自定义模板
cat <<'EOF' > ./Chart.yaml
name: hello-world
version: 1.0.0
EOF
# 创建模板文件, 用于生成 Kubernetes 资源清单(manifests) $ mkdir ./templates $ cat <<'EOF' > ./templates/deployment.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: hello-world spec: replicas: 1 template: metadata: labels: app: hello-world spec: containers: - name: hello-world image: hub.atguigu.com/library/nginx:latest ports: - containerPort: 80 protocol: TCP EOF $ cat <<'EOF' > ./templates/service.yaml apiVersion: v1 kind: Service metadata: name: hello-world spec: type: NodePort ports: - port: 80 targetPort: 80 protocol: TCP selector: app: hello-world EOF
helm的命令
$ helm ls
# 查询一个特定的 Release 的状态
$ helm status RELEASE_NAME
# 移除所有与这个 Release 相关的 Kubernetes 资源
$ helm delete cautious-shrimp
# helm rollback RELEASE_NAME REVISION_NUMBER
$ helm rollback cautious-shrimp 1
# 使用 helm delete --purge RELEASE_NAME 移除所有与指定 Release 相关的 Kubernetes 资源和所有这个
Release 的记录
$ helm delete --purge cautious-shrimp
$ helm ls --deleted
安装Dashboard
Q1: 更新repo https://blog.csdn.net/zhu13637053367/article/details/116943605
cd /root/install-k8s/helm/plugin/dashboard/kubernetes-dashboard
helm install . -n kubernetes-dashboard --namespace kube-system -f kubernetes-dashboard.yaml
修改svc的nodeport
获取secret-token
kubectl -n kube-system get secret |grep kubernetes-dashboard-token
kubectl -n kube-system describe secret kubernetes-dashboard-token-nrhww
posted on 2022-05-11 10:14 biyangqiang 阅读(63) 评论(0) 编辑 收藏 举报