首页 > 其他分享 >K8S 使用Minikube快速搭建K8S集群v1.24.0+(单机版)+CRI-Docker

K8S 使用Minikube快速搭建K8S集群v1.24.0+(单机版)+CRI-Docker

时间:2023-02-01 14:00:51浏览次数:183  
标签:cri 单机版 CRI minikube dockerd docker K8S root Docker

参考文档:https://minikube.sigs.k8s.io/docs/start/

系统版本:CentOS Linux release 7.6.1810 (Core)
软件版本:Docker-ce-18.06.0、Kubernetes-v1.24.0+
硬件要求:建议最低2核4GB

1、配置系统环境

# 配置主机名
[root@localhost ~]# echo 'minikube' >/etc/hostname
[root@localhost ~]# cat /etc/hostname |xargs hostname
[root@localhost ~]# bash
# 配置主机解析
[root@localhost ~]# cat <<EOF >> /etc/hosts
172.16.254.136 minikube
EOF
# 关闭防火墙
[root@minikube ~]# systemctl stop firewalld
[root@minikube ~]# systemctl disable firewalld
# 关闭SELinux
[root@minikube ~]# setenforce 0
[root@minikube ~]# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux
# 关闭SWAP交换分区
[root@minikube ~]# swapoff -a

2、安装Docker

# 配置YUM-Docker源
# Docker-YUM源由阿里巴巴开源镜像网提供。
[root@minikube ~]# yum -y install epel-release.noarch yum-utils
[root@minikube ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装依赖
[root@minikube ~]# yum -y install device-mapper-persistent-data lvm2
# 查看能安装的Docker版本
[root@minikube ~]# yum list docker-ce.x86_64 --showduplicates | sort -r
# 安装Docker
[root@minikube ~]# yum -y install docker-ce-18.06.0.ce-3.el7
# 启动Docker服务
[root@minikube ~]# systemctl start docker
[root@minikube ~]# systemctl enable docker
[root@minikube ~]# systemctl status docker
# 配置Docker使用国内镜像源
[root@minikube ~]# cat <<EOF > /etc/docker/daemon.json
{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}
EOF
# 重启Docker服务
[root@minikube ~]# systemctl restart docker
[root@minikube ~]# systemctl status docker

3、安装Kubectl、Kubernets-cni

[root@minikube ~]# 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
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
[root@minikube ~]# yum install kubectl kubernetes-cni -y --nogpgcheck

4.安装CRI-Docker、Crictl

安装最新版本的Kubernetesv1.24.0+,需要额外安装CRI-Docker

CRI-Docker为Kubernetes提供一个操作Docker的运行时接口。
Crictl用于Kubelet容器运行时接口 (CRI) 的CLI和验证工具。

参考文档:https://github.com/Mirantis/cri-dockerd、https://github.com/kubernetes-sigs/cri-tools

# 安装CRI-Docker
[root@minikube ~]# wget https://ghproxy.com/https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.1/cri-dockerd-0.3.1.amd64.tgz
[root@minikube ~]# tar xzvf cri-dockerd-0.3.1.amd64.tgz 
cri-dockerd/
cri-dockerd/cri-dockerd
[root@minikube ~]# cp cri-dockerd/cri-dockerd /usr/bin/

# 配置CRI-Docker作为SYSTEM系统服务
# 参考文件: https://github.com/Mirantis/cri-dockerd/tree/master/packaging/systemd
# 创建cri-docker.service文件
# 这边启动参数需要设置为ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7
[root@minikube ~]# vim /usr/lib/systemd/system/cri-docker.service
[Unit]
Description=CRI Interface for Docker Application Container Engine
Documentation=https://docs.mirantis.com
After=network-online.target firewalld.service docker.service
Wants=network-online.target
Requires=cri-docker.socket

[Service]
Type=notify
ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
Delegate=yes
KillMode=process

[Install]
WantedBy=multi-user.target

# 创建cri-docker.socket文件
[root@minikube ~]# vim /usr/lib/systemd/system/cri-docker.socket
[Unit]
Description=CRI Docker Socket for the API
PartOf=cri-docker.service

[Socket]
ListenStream=%t/cri-dockerd.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

# 启动CRI-Docker服务并设置为开机自启
[root@minikube ~]# systemctl daemon-reload
[root@minikube ~]# systemctl restart cri-docker
[root@minikube ~]# systemctl status cri-docker
● cri-docker.service - CRI Interface for Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/cri-docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2023-01-31 21:32:54 EST; 4s ago
     Docs: https://docs.mirantis.com
 Main PID: 13701 (cri-dockerd)
    Tasks: 9
   Memory: 14.2M
   CGroup: /system.slice/cri-docker.service
           └─13701 /usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7

Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Start docker client with request timeout 0s"
Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Hairpin mode is set to none"
Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Loaded network plugin cni"
Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Docker cri networking managed by network plugin cni"
Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Docker Info: &{ID:I32G:GCJA:CKTO:5ZIC:2AED:6KYI...] [Nativ
Jan 31 21:32:54 minikube systemd[1]: Started CRI Interface for Docker Application Container Engine.
Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Setting cgroupDriver cgroupfs"
Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Docker cri received runtime config &RuntimeConf...dr:,},}"
Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Starting the GRPC backend for the Docker CRI interface."
Jan 31 21:32:54 minikube cri-dockerd[13701]: time="2023-01-31T21:32:54-05:00" level=info msg="Start cri-dockerd grpc backend"
Hint: Some lines were ellipsized, use -l to show in full.
[root@minikube ~]# systemctl enable cri-docker
Created symlink from /etc/systemd/system/multi-user.target.wants/cri-docker.service to /usr/lib/systemd/system/cri-docker.service.

# 安装crictl
[root@minikube ~]# VERSION="v1.26.0"
[root@minikube ~]# wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
[root@minikube ~]# sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
[root@minikube ~]# rm -f crictl-$VERSION-linux-amd64.tar.gz
[root@minikube ~]# ln /usr/local/bin/crictl /usr/bin

5、安装Minikube

[root@minikube ~]# curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
[root@minikube ~]# install minikube-linux-amd64 /usr/local/bin/minikube
[root@minikube ~]# minikube version

6、使用Minikube创建一个Kubernetes单点集群

[root@minikube ~]# minikube start --vm-driver=none --kubernetes-version=latest --image-mirror-country='cn' --cri-socket='/var/run/cri-dockerd.sock'
# --vm-driver=none             表示使用Linux本机作为运行环境。
# --kubernetes-version=lastest 表示指定Kubernetes的版本。
# --image-mirror-country='cn'  表示使用中国地区的镜像。

7、查看Kubernetes集群运行情况

[root@minikube ~]# minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
timeToStop: Nonexistent

8、开启Dashboard

我们可以使用一个WEB UI图形化界面查看和管理Kubernetes集群。

# 启用仪表盘
# 使用Minikube启动仪表盘后,会打印一个URL,我们可以通过URL访问到仪表盘。
[root@minikube ~]# nohup minikube dashboard &
Opening http://127.0.0.1:37008/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ in your default browser...
# 外部访问到仪表盘
# 默认情况下开放的地址只允许本地访问,若想要外部访问到仪表盘,则需要暴露一个代理,允许外部访问。
# 由于URL路径较长,要使用Google浏览器访问,或者可以使用Nginx反向代理缩短URL长度。
[root@minikube ~]# nohup kubectl proxy --port="8001" --address="172.16.254.136" --accept-hosts="^.*" &
http://172.16.254.136:8001/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/

标签:cri,单机版,CRI,minikube,dockerd,docker,K8S,root,Docker
From: https://www.cnblogs.com/RidingWind/p/17082337.html

相关文章

  • JavaScript 输入一个数 返回 2数相乘 使得 2数尽可能接近
    functiongetRC(pageCount){vara=Math.round(Math.sqrt(pageCount));for(vari=0;i<10;i++){varb=pageCount/(a+i);if(b===Math.round(b))......
  • Ai JavaScript 把桌面下面 所有的png 图片导入到 ai里面的 脚本 获取某目录下所有文件
    vardoc=app.activeDocument;//创建一个目录varinput=newFolder("C:\\Users\\Administrator\\Desktop");//获取input目录下面的所有png图片得到一个数组对象vard......
  • Illustrator JavaScript 出血
    IllustratorJavaScript出血vardoc=app.activeDocument;varpt=72/25.4;varrc=1*pt;varls=6*pt;for(vari=0;i<doc.selection.length;i++){varshape=d......
  • 基于k8s的zookeeper搭建
    1.官方文档  https://kubernetes.io/zh-cn/docs/tutorials/stateful-application/zookeeper/2.k8s部署2.1.部署文件zookeeper.yamlapiVersion:v1kind:Service......
  • JavaScript奇技淫巧:操控URL
    JavaScript奇技淫巧:操控URL本文展示两种不常见的JS编程技巧:实现操控浏览器窗口,更改父窗口和子窗口的URL地址。修改父窗口URL当使用window.open()打开一个窗口,可以用window.......
  • 面试官:你说说 JavaScript 中类型的转换机制
    前言面试官:“你说说JavaScript中类型的转换机制”紧张的萌新:“字符串跟其他类型拼接会变成字符串...”面试官:“...”······大家好,我是CoderBin。又来到了面试官......
  • JavaScript 中更安全的 URL 读写
    前言URL对于我们开发人员来讲,应该是非常熟悉了。在对URL进行参数拼接时,我们一般都会直接进行字符串拼接或使用模版字符串,因为这样非常方便,但是我们这样其实会在不知不觉中......
  • TypeScript基础的使用
    一、类型注释类型注释=>作用:给js添加类型约束,约束是什么类型,就需要是什么类型语法=>类型letnum:Number=18conststr:String='张三'console.log(num);con......
  • k8s最佳实践:cgroup kmem的内存泄露问题
    k8s最佳实践:cgroupkmem的内存泄露问题1.前言这篇文章的全称应该叫:[在某些内核版本上,cgroup的kmemaccount特性有内存泄露问题],如果你遇到过pod的"cannotallocated......
  • express_javscript_webframe
    D:\code3\socketio_express_mongodb\ExpressJS-SocketIO-Boilerplate\config.js/***Webserverport*/constSERVER_PORT=3005;/***Sessionsettings*/co......