Minikube部署单节点Kubernetes

1.1 Minikube部署单节点K8s

  • Minikube是由Kubernetes社区维护的单机版的Kubernetes集群,支持macOS, Linux, andWindows等多种操作系统平台,使用最新的官方stable版本,并支持Kubernetes的大部分功能,从基础的容器编排管理,到高级特性如负载均衡、Ingress,权限控制等。非常适合作为Kubernetes入门,或开发测试环境使用。Minikube实际是跑在本地的虚拟机中的,所以,需要先安装一套Hypervisor。

  • 官方地址:minikube start | minikube

1.1.1 安装部署Docker-ce

复制代码
[root@minikube ~]# wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
[root@minikube ~]# sed -i 's+download.docker.com+mirrors.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
[root@minikube ~]# sed -i 's/$releasever/7Server/g' /etc/yum.repos.d/docker-ce.repo
[root@minikube ~]# yum install docker-ce -y
[root@minikube ~]# tee /etc/docker/daemon.json <<-'EOF'
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": [
"https://dbckerproxy.com",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://ccr.ccs.tencentyun.com"
]
}
EOF
​
[root@minikube ~]# systemctl daemon-reload
[root@minikube ~]# systemctl enable --now docker.service
[root@minikube ~]# docker --version
Docker version 20.10.21, build baeda1f

1.1.2 安装Minikube

复制代码
[root@minikube ~]# wget -c https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm
[root@minikube ~]# yum install minikube-latest.x86_64.rpm -y
[root@minikube ~]# minikube version
minikube version: v1.33.1
commit: 5883c09216182566a63dff4c326a6fc9ed2982ff
[root@minikube ~]# curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
[root@minikube ~]# install minikube-linux-amd64 /usr/local/bin/minikube

1.1.3 禁用swap分区

复制代码
[root@minikube ~]# sed -i 's/.*swap.*/# &/' /etc/fstab
[root@minikube ~]# swapoff -a

1.1.4 安装kubectl

复制代码
[root@minikube ~]# curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
[root@minikube ~]# chmod +x ./kubectl
[root@minikube ~]# mv kubectl /usr/local/bin/
[root@minikube ~]# kubectl version --client
Client Version: v1.30.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3

1.1.5 升级内核并配置参数

复制代码
[root@minikube ~]# cat > /etc/sysctl.d/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
vm.overcommit_memory=1
vm.panic_on_oom=0
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
​
[root@minikube ~]# sysctl -p /etc/sysctl.d/kubernetes.conf

1.1.6 安装cri-docker

复制代码
[root@minikube ~]# wget -c https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.13/cri-dockerd-0.3.13-3.el7.x86_64.rpm
[root@minikube ~]# yum install cri-dockerd-0.3.13-3.el7.x86_64.rpm -y
[root@minikube ~]# sed -i 's#^ExecStart=.*#ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.9#' /usr/lib/systemd/system/cri-docker.service
[root@minikube ~]# systemctl daemon-reload
[root@minikube ~]# systemctl restart docker
[root@minikube ~]# systemctl enable --now cri-docker.service

1.1.7 安装crictl

复制代码
[root@minikube ~]# VERSION="v1.30.0"
[root@minikube ~]# wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
[root@minikube ~]# tar zxf crictl-$VERSION-linux-amd64.tar.gz -C /usr/bin
[root@minikube ~]# rm -f crictl-$VERSION-linux-amd64.tar.gz

1.1.8 启动minikube

复制代码
[root@minikube ~]# yum install conntrack -y
[root@minikube ~]# minikube start --vm-driver=none --image-mirror-country=cn --registry-mirror='https://ckdhnbk9.mirror.aliyuncs.com' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --driver=docker --force

1.1.9 检查服务是否正常

复制代码
[root@minikube ~]# mv /root/.kube /root/.minikube $HOME
[root@minikube ~]# chown -R $USER $HOME/.kube $HOME/.minikube
[root@minikube ~]# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS    MESSAGE   ERROR
controller-manager   Healthy   ok        
scheduler            Healthy   ok        
etcd-0               Healthy   ok        
​
[root@minikube ~]# kubectl get node
NAME       STATUS   ROLES           AGE   VERSION
minikube   Ready    control-plane   22m   v1.30.0
[root@minikube ~]# minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
​
[root@minikube ~]# kubectl get pod -n kube-system
NAME                               READY   STATUS             RESTARTS        AGE
coredns-7db6d8ff4d-7ztfs           1/1     Running            1 (84s ago)    22m
etcd-minikube                      1/1     Running            1 (9m45s ago)   22m
kube-apiserver-minikube            1/1     Running            1 (3m20s ago)   22m
kube-controller-manager-minikube   1/1     Running            1 (9m45s ago)   22m
kube-proxy-dfqnf                   1/1     Running            1 (9m45s ago)   22m
kube-scheduler-minikube            1/1     Running            1 (9m45s ago)   22m
storage-provisioner                1/1     Running            3 (2m34s ago)   22m
相关推荐
年薪丰厚1 小时前
如何在K8S集群中查看和操作Pod内的文件?
docker·云原生·容器·kubernetes·k8s·container
zhangj11251 小时前
K8S Ingress 服务配置步骤说明
云原生·容器·kubernetes
岁月变迁呀1 小时前
kubeadm搭建k8s集群
云原生·容器·kubernetes
墨水\\1 小时前
二进制部署k8s
云原生·容器·kubernetes
Source、1 小时前
k8s-metrics-server
云原生·容器·kubernetes
上海运维Q先生1 小时前
面试题整理15----K8s常见的网络插件有哪些
运维·网络·kubernetes
颜淡慕潇1 小时前
【K8S问题系列 |19 】如何解决 Pod 无法挂载 PVC问题
后端·云原生·容器·kubernetes
大熊程序猿4 小时前
K8s证书过期
云原生·容器·kubernetes
魏 无羡13 小时前
linux CentOS系统上卸载docker
linux·kubernetes·centos
Karoku06613 小时前
【k8s集群应用】kubeadm1.20高可用部署(3master)
运维·docker·云原生·容器·kubernetes