Centos7 yum部署单机kubernetes集群
Posted sre-chan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7 yum部署单机kubernetes集群相关的知识,希望对你有一定的参考价值。
kubernetes有多种部署方式,目前主流的方式有kubeadm、minikube、二进制包
- minikube:一个用于快速搭建单节点kubernetes的工具
- kubeadm:一个用于快速搭建kubernetes集群的工具
- 二进制包 :从官网下载每个组件的二进制包,依次去安装,此方式对于理解kubernetes组件更加有效
一、Minikube
1、安装docker-ce,使用阿里云镜像
PS:此步骤三台服务器上均部署
安装教程:https://developer.aliyun.com/mirror/docker-ce
[root@k8s-master ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@k8s-master ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@k8s-master ~]# sed -i \'s+download.docker.com+mirrors.aliyun.com/docker-ce+\' /etc/yum.repos.d/docker-ce.repo
[root@k8s-master ~]# yum -y install docker-ce
[root@k8s-master ~]# systemctl enable --now docker.service
2、安装minikube
获取地址:https://github.com/kubernetes/minikube/releases/tag/v1.25.2
[root@k8s-master ~]# wget -c https://github.com/kubernetes/minikube/releases/download/v1.25.2/minikube-1.25.2-0.x86_64.rpm
[root@k8s-master ~]# scp minikube-1.25.2-0.x86_64.rpm 192.168.11.106:$PWD
[root@k8s-master ~]# scp minikube-1.25.2-0.x86_64.rpm 192.168.11.107:$PWD
[root@k8s-master ~]# rpm -ivh minikube-1.25.2-0.x86_64.rpm
[root@k8s-master ~]# minikube version
minikube version: v1.25.2
commit: 362d5fdc0a3dbee389b3d3f1034e8023e72bd3a7
安装完成之后运行启动命令minikube start --force --driver=docker --image-repository=http://registry.cn-hangzhou.aliyuncs.com/google_containers
[root@k8s-master ~]# minikube start --force --driver=docker --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
3、安装kubectl
[root@k8s-master ~]# curl -Lo kubectl http://kubernetes.oss-cn-hangzhou.aliyuncs.com/kubernetes-release/release/v1.22.1/bin/linux/amd64/kubectl
[root@k8s-node02 ~]# ll
total 61792
-rw-------. 1 root root 1428 Dec 30 22:07 anaconda-ks.cfg
-rw-r--r-- 1 root root 46907392 Jun 18 20:19 kubectl
-rw-r--r-- 1 root root 16360927 Jun 18 19:55 minikube-1.25.2-0.x86_64.rpm
[root@k8s-node02 ~]# mv kubectl /usr/bin/
[root@k8s-node02 ~]# chmod a+x /usr/bin/kubectl
检查版本
检查pods
四、常用命令
minikube 常用命令
# 检查安装结果
[root@k8s-master ~]# minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
[root@k8s-master ~]# kubectl version
Client Version: version.InfoMajor:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:45:37Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"
Server Version: version.InfoMajor:"1", Minor:"23", GitVersion:"v1.23.3", GitCommit:"816c97ab8cff8a1c72eccca1026f7820e93e0d25", GitTreeState:"clean", BuildDate:"2022-01-25T21:19:12Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"linux/amd64"
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane,master 21m v1.23.3
[root@k8s-master ~]# kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-65c54cc984-tbfp8 1/1 Running 0 22m
kube-system etcd-minikube 1/1 Running 0 22m
kube-system kube-apiserver-minikube 1/1 Running 0 22m
kube-system kube-controller-manager-minikube 1/1 Running 0 22m
kube-system kube-proxy-4g2qq 1/1 Running 0 22m
kube-system kube-scheduler-minikube 1/1 Running 0 22m
kube-system storage-provisioner 1/1 Running 0 22m
# 查询运行的 pod
[root@k8s-master ~]# minikube kubectl -- get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-65c54cc984-tbfp8 1/1 Running 0 23m
kube-system etcd-minikube 1/1 Running 0 23m
kube-system kube-apiserver-minikube 1/1 Running 0 23m
kube-system kube-controller-manager-minikube 1/1 Running 0 23m
kube-system kube-proxy-4g2qq 1/1 Running 0 23m
kube-system kube-scheduler-minikube 1/1 Running 0 23m
kube-system storage-provisioner 1/1 Running 0 23m
# 挂起虚拟机
[root@k8s-master ~]# minikube pause
* Pausing node minikube ...
* Paused 14 containers in: kube-system, kubernetes-dashboard, storage-gluster, istio-operator
# 停止虚拟机
minikube stop
# 修改虚拟机内存配置
minikube config set memory 16384
# 查看 minikube 的安装目录列表
minikube addons list
# 启动 dashboard 控制台
minikube dashboard
curl 127.0.0.1:23341
# 删除所有 minikube 虚拟机
minikube delete --all
# 部署目录
/var/lib/kubelet
/var/lib/minikube
# 使用minikube导入镜像,当本地镜像总是无法找到时,可以留意这个这种方式
minikube load xxx.tar
# 启动minikube
minikube start --force --driver=docker --image-repository=registry.cn-hangzhou.aliyuncs.com/go
k8s 常用命令
# 创建带有终端的 Pod,并进入(后续测试用)
kubectl run busybox --image=busybox -it
# 部署 app 进行测试
kubectl run nginx02 --image=nginx
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8081
# deployment
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment hello-minikube --type=NodePort --port=8080
kubectl get service hello-minikube
# 使用 minikube 访问服务
minikube service hello-minikube
# 使用端口映射访问服务
kubectl port-forward service/hello-minikube 7080:8080
curl http://localhost:7080/
# 使用 LB 类型的 deployment 测试
kubectl create deployment balanced --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment balanced --type=LoadBalancer --port=8080
minikube tunnel
kubectl get services balanced
作者:ChAn
-------------------------------------------
个性签名:今天做了别人不想做的事,明天你就做得到别人做不到的事,尝试你都不敢,你拿什么赢!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
以上是关于Centos7 yum部署单机kubernetes集群的主要内容,如果未能解决你的问题,请参考以下文章
初识Kubernetes(K8s):从一个单机部署实现Java Web应用例子开始