安装k8s

简介: 完成安装k8s集群以后,推荐使用[https://github.com/512team/dhorse](https://github.com/512team/dhorse)发布应用。## 准备环境准备两台服务器节点,如果需要安装虚拟机,可以参考[《wmware和centos安装过程》](https://blog.csdn.net/huashetianzu/article/details/109510266)| 机器名 | IP | 角色 | CPU | 内存 || :----: | :----: | :----: | :----: | :----: || centos01 |

完成安装k8s集群以后,推荐使用https://github.com/512team/dhorse发布应用。

准备环境

准备两台服务器节点,如果需要安装虚拟机,可以参考《wmware和centos安装过程》

机器名 IP 角色 CPU 内存
centos01 192.168.109.130 master 4核 2G
centos02 192.168.109.131 node 4核 2G
设置主机名,所有节点都执行
vim /etc/hosts
#增加
192.168.109.130 centos01
192.168.109.131 centos02
关闭防火墙,所有节点都执行
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/selinux/config
#修改SELINUX的值
SELINUX=disabled
关闭swap内存,所有节点都执行
swapoff -a
vim /etc/fstab
# 将该行注释掉
#/dev/mapper/cs-swap swap
配置网桥,所有节点都执行

1.修改参数

vim /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables     = 1
net.ipv4.ip_forward                 = 1
vm.swappiness                         = 0

2.然后,加载如下两个模块,所有节点都执行

modprobe ip_vs_rr
modprobe br_netfilter

3.生效配置

[root@centos01 opt]# sysctl -p
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness = 0

安装containerd

以下步骤所有节点都执行。

安装
wget https://github.com/containerd/containerd/releases/download/v1.7.2/containerd-1.7.2-linux-amd64.tar.gz
tar Cxzvf /usr/local containerd-1.7.2-linux-amd64.tar.gz
修改配置
mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
vim /etc/containerd/config.toml
#SystemdCgroup的值改为true
SystemdCgroup = true
#由于国内下载不到registry.k8s.io的镜像,修改sandbox_image的值为:
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"
启动服务
mkdir -p /usr/local/lib/systemd/system
wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
mv containerd.service /usr/local/lib/systemd/system
systemctl daemon-reload
systemctl enable --now containerd
验证安装
[root@centos01 opt]# ctr version
Client:
  Version:  v1.7.2
  Revision: 0cae528dd6cb557f7201036e9f43420650207b58
  Go version: go1.20.4

Server:
  Version:  v1.7.2
  Revision: 0cae528dd6cb557f7201036e9f43420650207b58
  UUID: 747cbf1b-17d4-4124-987a-203d8c72de7c

安装runc

以下步骤所有节点都执行。

准备文件
wget https://github.com//opencontainers/runc/releases/download/v1.1.7/runc.amd64
chmod +x runc.amd64
查找containerd安装时已安装的runc所在的位置,如果不存在runc文件,则直接进行下一步
[root@centos01 opt]# which runc
/usr/bin/runc
替换上一步的结果文件
mv -f runc.amd64 /usr/bin/runc
验证安装
[root@centos01 opt]# runc -v
runc version 1.1.7
commit: v1.1.7-0-g860f061b
spec: 1.0.2-dev
go: go1.20.3
libseccomp: 2.5.4

安装kubernetes

添加阿里云的kubernetes源,所有节点都执行
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
安装最新版,所有节点都执行
yum install -y kubeadm kubelet kubectl
开机自启动,所有节点都执行
systemctl enable kubelet
验证安装,所有节点都执行
[root@centos01 opt]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.1", GitCommit:"4c9411232e10168d7b050c49a1b59f6df9d7ea4b", GitTreeState:"clean", BuildDate:"2023-04-14T13:20:04Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"linux/amd64"}
初始化集群,仅在master(centos01)上执行
[root@centos01 opt]# kubeadm init --apiserver-advertise-address 192.168.109.130 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.27.1 --pod-network-cidr=10.244.0.0/16

...
...
...

Your Kubernetes control-plane 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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

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/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.109.130:6443 --token osh87v.zvo010kamsr8esmp \
    --discovery-token-ca-cert-hash sha256:ff4607c7c194e9f756b1eb509e64d2d926b5f8f9556a85c3c14a2d25add28230

其中,
–apiserver-advertise-address:通告侦听地址
–image-repository:指定镜像地址使用阿里云的,默认会使用谷歌镜像
–kubernetes-version:指定当前的kubernetes的版本
–pod-network-cidr=10.244.0.0/16:flannel网络的固定地址范围

仔细阅读kubeadm init执行的结果,根据提示,还需要进行3步操作

1.笔者用的是root用户,仅在master节点执行

[root@centos01 opt]# vim /etc/profile
#在最后一行增加
export KUBECONFIG=/etc/kubernetes/admin.conf

生效环境变量

[root@centos01 opt]# source /etc/profile

2.安装网络插件,可以选择calico或flannel,这里选择安装flannel,仅在master节点执行

下载安装文件

[root@centos01 opt]# wget https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

修改配置

[root@centos01 opt]# vim kube-flannel.yml
#修改Network项的值,改为和--pod-network-cidr一样的值
"Network": "10.244.0.0/16"
#由于有时国内网络的问题,需要修改image的地址,把所有的docker.io改为dockerproxy.com
#共需要修改3处,两个值
image: dockerproxy.com/flannel/flannel:v0.22.0
image: dockerproxy.com/flannel/flannel-cni-plugin:v1.1.2

安装网络插件

[root@centos01 opt]# kubectl apply -f kube-flannel.yml

验证安装

[root@centos01 opt]# kubectl get pods -n kube-flannel
NAME                    READY   STATUS    RESTARTS       AGE
kube-flannel-ds-dfngh   1/1     Running   17 (13m ago)   6d1h
kube-flannel-ds-qll8g   1/1     Running   12 (13m ago)   6d1h

3.其他节点加入集群,非master节点都执行

[root@centos02 opt]# kubeadm join 192.168.109.130:6443 --token osh87v.zvo010kamsr8esmp --discovery-token-ca-cert-hash sha256:ff4607c7c194e9f756b1eb509e64d2d926b5f8f9556a85c3c14a2d25add28230
验证安装结果,仅在master节点执行
[root@centos01 opt]# kubectl get nodes
NAME       STATUS   ROLES           AGE    VERSION
centos01   Ready    control-plane   134m   v1.27.1
centos02   Ready    <none>          133m   v1.27.1
[root@centos01 opt]# kubectl get pods -n kube-system
NAME                               READY   STATUS    RESTARTS   AGE
coredns-7bdc4cb885-l4vs2           1/1     Running   0          9m3s
coredns-7bdc4cb885-wzc8x           1/1     Running   0          9m3s
etcd-centos01                      1/1     Running   0          9m18s
kube-apiserver-centos01            1/1     Running   0          9m18s
kube-controller-manager-centos01   1/1     Running   0          9m19s
kube-proxy-m92hr                   1/1     Running   0          28s
kube-proxy-pv4hw                   1/1     Running   0          9m3s
kube-scheduler-centos01            1/1     Running   0          9m18s

建议重启一遍所有服务器节点,有可能会暴露出来隐藏的问题,再次验证以上结果,仍然正常。

最后,推荐一个部署应用的平台: https://github.com/512team/dhorse

演示地址:http://dhorse-demo2.512.team

相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务&nbsp;ACK 容器服务&nbsp;Kubernetes&nbsp;版(简称&nbsp;ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情:&nbsp;https://www.aliyun.com/product/kubernetes
相关文章
|
8天前
|
Kubernetes Linux 网络安全
kubeadm安装k8s
该文档提供了一套在CentOS 7.6上安装Docker和Kubernetes(kubeadm)的详细步骤,包括安装系统必备软件、关闭防火墙和SELinux、禁用swap、开启IP转发、设置内核参数、配置Docker源和加速器、安装指定版本Docker、启动Docker、设置kubelet开机启动、安装kubelet、kubeadm、kubectl、下载和配置Kubernetes镜像、初始化kubeadm、创建kubeconfig文件、获取节点加入集群命令、下载Calico YAML文件以及安装Calico。这些步骤不仅适用于v1.19.14,也适用于更高版本。
102 1
|
8天前
|
Kubernetes 容器
安装ipvsadm并且k8s开启IPVS模式
安装ipvsadm并且k8s开启IPVS模式
16 0
|
8天前
|
Kubernetes Linux Docker
kubeadm安装Kubernetes
kubeadm安装Kubernetes
38 0
|
8天前
|
Kubernetes 关系型数据库 Linux
linux安装centos7 kubenetes 单机版安装k8s
linux安装centos7 kubenetes 单机版安装k8s
53 0
|
8天前
|
Kubernetes 测试技术 API
ChaosBlade常见问题之安装K8S探针心跳检测失败如何解决
ChaosBlade 是一个开源的混沌工程实验工具,旨在通过模拟各种常见的硬件、软件、网络、应用等故障,帮助开发者在测试环境中验证系统的容错和自动恢复能力。以下是关于ChaosBlade的一些常见问题合集:
35 0
|
8天前
|
Kubernetes 应用服务中间件 nginx
Kubernetes服务网络Ingress网络模型分析、安装和高级用法
Kubernetes服务网络Ingress网络模型分析、安装和高级用法
54 5
|
8天前
|
存储 Kubernetes 监控
KubeSphere平台安装系列之一【Kubernetes上安装KubeSphere(亲测--实操完整版)】(1/3)
KubeSphere平台安装系列之一【Kubernetes上安装KubeSphere(亲测--实操完整版)】(1/3)
45 0
|
8天前
|
存储 Kubernetes 监控
K8S集群上安装KubeSphere的详细过程
K8S集群上安装KubeSphere的详细过程
46 0
|
8天前
|
Kubernetes Linux Docker
深度解析:Kubernetes 1.28.2集群安装过程中的关键步骤
本文旨在为读者提供一份详尽的Kubernetes 1.28.2集群安装指南,帮助您从零开始构建稳定、高效的Kubernetes集群。我们将从环境准备、软件安装、集群初始化到节点添加等各个环节进行逐步讲解,确保您能够顺利完成集群的搭建。
|
8天前
|
运维 Kubernetes API
kubernetes 安装 kubernetes-dashboard 7.x
kubernetes 安装 kubernetes-dashboard 7.x
84 0