Kubernetes :::info 前提条件:
- 访问主机CentOS8的和Docker的驱动不兼容,所以不能使用CentOS8以上系列的服务主机
- 2核CPU的服务主机(必要)
- 大于2G 内存的服务器主机[大于2G是为了防止其他硬件占用内存导致Kubernetes的使用内存不足的问题](必要)
- 这里的驱动是基于Docker,如果未安装则需要安装启动Docker,执行命令:
yum install -y docker
:::1、安装minikube
minikube-latest.x86_64.ziprpm -Uvh minikube-latest.x86_64.rpm
2、CentOS安装kubectl
```bash华为云的镜像仓库
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://repo.huaweicloud.com/kubernetes/yum/repos/kubernetes-el7-\$basearch enabled=1 gpgcheck=1 repo_gpgcheck=0 gpgkey=https://repo.huaweicloud.com/kubernetes/yum/doc/yum-key.gpg https://repo.huaweicloud.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
阿里云的镜像仓库
cat <
yum -y install kubelet kubeadm kubectl kubernetes-cni
<a name="AdwVc"></a>
## 3、创建非root用户以及Docker组,并授权
```bash
useradd fcant
passwd fcant
groupadd docker
usermod -aG docker fcant
:::tips
注意:如果在创建非root用户时已经启动Docker,则需要在用户授权成功后重启Docker使授权生效。
执行命令:systemctl restart docker
避免的问题:
在非root用户启动时,导致无法读取的权限错误。
:::
4、为非root用户授予root用户权限
:::tips
防止后面的操作中出现创建的非root用户没有权限的错误
:::
sudo visudo
# 或者下面的命令、vim编辑时有高亮提示
vim /etc/sudoers
5、切换非root用户,启动minikube
国内存在网络问题,所以启动时指定了镜像仓库地址
$ su fcant
$ minikube start --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
😄 minikube v1.20.0 on Centos 7.6.1810 (amd64)
✨ Using the docker driver based on existing profile
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
> index.docker.io/kicbase/sta...: 358.10 MiB / 358.10 MiB 100.00% 2.78 MiB
🤷 docker "minikube" container is missing, will recreate.
🔥 Creating docker container (CPUs=2, Memory=2200MB) ...
🐳 Preparing Kubernetes v1.20.2 on Docker 20.10.6 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔎 Verifying Kubernetes components...
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetesui/dashboard:v2.1.0@sha256:7f80b5ba141bead69c4fee8661464857af300d7d7ed0274cf7beecedc00322e6 (global image repository)
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-minikube/storage-provisioner:v5 (global image repository)
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetesui/metrics-scraper:v1.0.4@sha256:555981a24f184420f3be0c79d4efb6c948a85cfce84034f85a563f4151a81cbf (global image repository)
🌟 Enabled addons: default-storageclass, storage-provisioner, dashboard
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
6、配置tunnel外网访问服务
如果未配置tunnel,EXTERNAL-IP列显示的是pending状态
由于应用部署在集群内部,集群有自己对应的IP,所以外网无法访问,需要用到tunnel。
$ minikube tunnel
[sudo] password for fcant:
Status:
machine: minikube
pid: 76873
route: 10.96.0.0/12 -> 192.168.49.2
minikube: Running
services: [ingress-nginx]
errors:
minikube: no errors
router: no errors
loadbalancer emulator: no errors
Status:
machine: minikube
pid: 76873
route: 10.96.0.0/12 -> 192.168.49.2
minikube: Running
services: [ingress-nginx]
errors:
minikube: no errors
router: no errors
loadbalancer emulator: no errors
注意该命令执行需要输入当前用户的登录密码,命令执行示例如下:
然后再检查EXTERNAL-IP,可以发现已经有正确的IP了,并且使用curl去访问能得到正确的响应。