说下为啥选择云环境,最开始在本地电脑上安装的minikube,但是由于国内的网络访问不了谷歌的镜像仓库,安装ingress-nginx或者其他插件时着实的恶心。要不翻墙,要不自己搭建个镜像仓库。最终决定用阿里云境外的节点,按小时收费的那种,一个小时大概也就3毛钱。随时释放,不会因为这些环境和网络的问题分神。
1.准备环境
阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台
没有账号注册一个,或者使用支付宝登陆。这里就不做赘述了。
选择“云服务ECS”
创建实例
一定选择国外的节点 ,我选择是韩国首尔的节点,这个便宜。CPU2核,内存2G。操作系统选的是ubuntu18.04(看自己喜好linux哪个都行),磁盘不用修改40G和20G一样钱。
下一步网络设置。需要自建一个交换机和安全组,就按推荐的建。分配公网IP选上,按流量收费。
下一步系统配置,配置自定义密码登陆的方式,给root用户设置一个秘密,设置个自己喜欢的。
确认订单。创建实例。账户需要有100块钱(按时间扣费用)。
控制台多了刚才创建的实例,我刚新建的外网ip是8.213.130.127(基本用几个小时我就释放了,不怕暴露),此时在你机器的本地就可以通过ssh对这台机器登陆了。
补充下安全组,默认创建的安全组会开放22、80端口,所以本机才可以使用ssh登陆。
本地登陆
ssh root@8.213.130.127
2.安装docker
apt-get update
apt install docker.io
root@iZmj7hlj4my4j4dgaiq763Z:~# apt install docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
bridge-utils containerd dns-root-data dnsmasq-base git git-man libcurl3-gnutls liberror-perl pigz runc ubuntu-fan
Suggested packages:
ifupdown aufs-tools btrfs-progs cgroupfs-mount | cgroup-lite debootstrap docker-doc rinse zfs-fuse | zfsutils git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs
git-mediawiki git-svn
The following NEW packages will be installed:
bridge-utils containerd dns-root-data dnsmasq-base docker.io git git-man libcurl3-gnutls liberror-perl pigz runc ubuntu-fan
0 upgraded, 12 newly installed, 0 to remove and 55 not upgraded.
Need to get 71.0 MB of archives.
After this operation, 327 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Y就行了。安装完查看docker版本
root@iZmj7hlj4my4j4dgaiq763Z:~# docker -v
Docker version 20.10.21, build 20.10.21-0ubuntu1~18.04.2
3.安装minikube
Welcome! | minikube
可以参考官网。选择下Linux、x86-64、stable、binary download
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
下载安装包
root@iZmj7hlj4my4j4dgaiq763Z:~# curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 80.0M 100 80.0M 0 0 9874k 0 0:00:08 0:00:08 --:--:-- 12.2M
安装
sudo install minikube-linux-amd64 /usr/local/bin/minikube
启动
minikube start
提示xxx,直接加一个--force。
root@iZmj7hlj4my4j4dgaiq763Z:~# minikube start
😄 minikube v1.30.1 on Ubuntu 18.04 (amd64)
✨ Automatically selected the docker driver. Other choices: ssh, none
🛑 The "docker" driver should not be used with root privileges. If you wish to continue as root, use --force.
💡 If you are running minikube within a VM, consider using --driver=none:
📘 https://minikube.sigs.k8s.io/docs/reference/drivers/none/
❌ Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
minikube start --force
启动成功,还有一个提示是内存小于最小内存1900MB了。学习环境不用理这个错误。
root@iZmj7hlj4my4j4dgaiq763Z:~# minikube start --force
😄 minikube v1.30.1 on Ubuntu 18.04 (amd64)
❗ minikube skips various validations when --force is supplied; this may lead to unexpected behavior
✨ Automatically selected the docker driver. Other choices: none, ssh
🛑 The "docker" driver should not be used with root privileges. If you wish to continue as root, use --force.
💡 If you are running minikube within a VM, consider using --driver=none:
📘 https://minikube.sigs.k8s.io/docs/reference/drivers/none/
⛔ Requested memory allocation (1889MB) is less than the recommended minimum 1900MB. Deployments may fail.
🧯 The requested memory allocation of 1889MiB does not leave room for system overhead (total system memory: 1889MiB). You may face stability issues.
💡 Suggestion: Start minikube with less memory allocated: 'minikube start --memory=1889mb'
📌 Using Docker driver with root privileges
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
💾 Downloading Kubernetes v1.26.3 preload ...
> preloaded-images-k8s-v18-v1...: 397.02 MiB / 397.02 MiB 100.00% 6.80 Mi
> gcr.io/k8s-minikube/kicbase...: 373.53 MiB / 373.53 MiB 100.00% 4.50 Mi
🔥 Creating docker container (CPUs=2, Memory=1889MB) ...
🐳 Preparing Kubernetes v1.26.3 on Docker 23.0.2 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🔎 Verifying Kubernetes components...
🌟 Enabled addons: storage-provisioner, default-storageclass
💡 kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
3.安装kubectl
在 Linux 系统中安装并设置 kubectl | Kubernetes
curl -LO https://dl.k8s.io/release/v1.26.0/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
查看版本
kubectl version
root@iZmj7hlj4my4j4dgaiq763Z:~# kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.0", GitCommit:"b46a3f887ca979b1a5d14fd39cb1af43e7e5d12d", GitTreeState:"clean", BuildDate:"2022-12-08T19:58:30Z", GoVersion:"go1.19.4", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.3", GitCommit:"9e644106593f3f4aa98f8a84b23db5fa378900bd", GitTreeState:"clean", BuildDate:"2023-03-15T13:33:12Z", GoVersion:"go1.19.7", Compiler:"gc", Platform:"linux/amd64"}
4.通过kubectl查看刚启动minikube
kubectl get pod -A
root@iZmj7hlj4my4j4dgaiq763Z:~# kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-787d4945fb-dxzrl 1/1 Running 0 5m12s
kube-system etcd-minikube 1/1 Running 0 5m24s
kube-system kube-apiserver-minikube 1/1 Running 0 5m24s
kube-system kube-controller-manager-minikube 1/1 Running 0 5m24s
kube-system kube-proxy-g9n8f 1/1 Running 0 5m12s
kube-system kube-scheduler-minikube 1/1 Running 0 5m24s
kube-system storage-provisioner 1/1 Running 1 (4m41s ago) 5m23s
5.安装ingress-nginx
在 Minikube 环境中使用 NGINX Ingress 控制器配置 Ingress | Kubernetes
这里就不截图了,安装上面地址一步一步执行,全部都可以成功。亲测。
6.释放ECS实例
不用的时候可以直接释放了。资源配置旁边的点点点。藏的有点深,搜索下“释放”。