文章目录
- 1. 安装依赖 tools
- 2. 安装 docker
- 3. 安装 minikube
- 4. 安装 kubectl
- 5. minikube 创建 kubernetes 集群
- 6. 查看
–
1. 安装依赖 tools
配置linux yum 源
yum -y update
yum -y install apt-transport-https ca-certificates curl software-properties-common conntrack
2. 安装 docker
你可以根据docker官方寻找合适的安装方式
配置docker-ce源
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
查看docker-ce版本
yum list docker-ce --showduplicates | sort -r
安装
yum -y install docker-ce docker-ce-cli containerd.io
配置加速器地址
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ckdhnbk9.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl start docker
systemctl enable docker
查看docker版本
$ docker version
Client: Docker Engine - Community
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:49:57 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:48:24 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
3. 安装 minikube
你可以根据官方安装寻找适合自己的方式。
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo rpm -Uvh minikube-latest.x86_64.rpm
你可以使用阿里云源
curl -Lo minikube "https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/latest/minikube-linux-amd64" && chmod +x minikube && sudo mv minikube /usr/local/bin/
查看版本
$ minikube version
minikube version: v1.25.2
commit: 362d5fdc0a3dbee389b3d3f1034e8023e72bd3a7
4. 安装 kubectl
在kubernetes官方寻找kubectl安装方式 寻找国内合适的kubernetes yum源
yum -y install kubectl
查看版本
$ kubectl version --client -o json
{
"clientVersion": {
"major": "1",
"minor": "23",
"gitVersion": "v1.23.5",
"gitCommit": "c285e781331a3785a7f436042c65c5641ce8a9e9",
"gitTreeState": "clean",
"buildDate": "2022-03-16T15:58:47Z",
"goVersion": "go1.17.8",
"compiler": "gc",
"platform": "linux/amd64"
}
}
5. minikube 创建 kubernetes 集群
没有参数它会报以下错误:
minikube start
* Centos 7.9.2009 上的 minikube v1.25.2
* 自动选择 docker 驱动。其他选项:none, ssh
* The "docker" driver should not be used with root privileges.
* If you are running minikube within a VM, consider using --driver=none:
* https://minikube.sigs.k8s.io/docs/reference/drivers/none/
X Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
正确的方式是:
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'
输出
* Centos 7.9.2009 上的 minikube v1.25.2
* 根据用户配置使用 none 驱动程序
X Requested memory allocation (1819MB) is less than the recommended minimum 1900MB. Deployments may fail.
X The requested memory allocation of 1819MiB does not leave room for system overhead (total system memory: 1819MiB). You may face stability issues.
* 建议:Start minikube with less memory allocated: 'minikube start --memory=1819mb'
* 正在使用镜像存储库 registry.cn-hangzhou.aliyuncs.com/google_containers
* Starting control plane node minikube in cluster minikube
* Running on localhost (CPUs=4, Memory=1819MB, Disk=17394MB) ...
* OS release is CentOS Linux 7 (Core)
* 正在 Docker 20.10.14 中准备 Kubernetes v1.23.3…
- kubelet.housekeeping-interval=5m
> kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubeadm: 43.12 MiB / 43.12 MiB [---------------] 100.00% 1.23 MiB p/s 35s
> kubectl: 44.43 MiB / 44.43 MiB [---------------] 100.00% 1.03 MiB p/s 43s
> kubelet: 118.75 MiB / 118.75 MiB [-------------] 100.00% 2.12 MiB p/s 56s
- Generating certificates and keys ...
- Booting up control plane ...
- Configuring RBAC rules ...
* 开始配置本地主机环境...
*
! The 'none' driver is designed for experts who need to integrate with an existing VM
* Most users should use the newer 'docker' driver instead, which does not require root!
* For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/
*
! kubectl 和 minikube 配置将存储在 /root 中
! 如需以您自己的用户身份使用 kubectl 或 minikube 命令,您可能需要重新定位该命令。例如,如需覆盖您的自定义设置,请运行:
*
- sudo mv /root/.kube /root/.minikube $HOME
- sudo chown -R $USER $HOME/.kube $HOME/.minikube
*
* 此操作还可通过设置环境变量 CHANGE_MINIKUBE_NONE_USER=true 自动完成
* Verifying Kubernetes components...
- Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
* Enabled addons: default-storageclass, storage-provisioner
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
6. 查看
6.1 查看集群配置信息
$ kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority: /root/.minikube/ca.crt
extensions:
- extension:
last-update: Mon, 28 Mar 2022 17:20:36 CST
provider: minikube.sigs.k8s.io
version: v1.25.2
name: cluster_info
server: https://192.168.211.51:8443
name: minikube
contexts:
- context:
cluster: minikube
extensions:
- extension:
last-update: Mon, 28 Mar 2022 17:20:36 CST
provider: minikube.sigs.k8s.io
version: v1.25.2
name: context_info
namespace: default
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
user:
client-certificate: /root/.minikube/profiles/minikube/client.crt
client-key: /root/.minikube/profiles/minikube/client.key
6.2 查看集群状态
$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
6.3 查看 node
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
localhost.localdomain Ready control-plane,master 5m24s v1.23.3
6.4 查看 pod
$ kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-65c54cc984-2cf5f 1/1 Running 0 5m48s
kube-system etcd-localhost.localdomain 1/1 Running 0 6m2s
kube-system kube-apiserver-localhost.localdomain 1/1 Running 0 6m
kube-system kube-controller-manager-localhost.localdomain 1/1 Running 0 6m
kube-system kube-proxy-khn4n 1/1 Running 0 5m49s
kube-system kube-scheduler-localhost.localdomain 1/1 Running 0 6m
kube-system storage-provisioner 1/1 Running 0 5m58s
6.5 查看集群信息
$ kubectl cluster-info
Kubernetes control plane is running at https://192.168.211.51:8443
CoreDNS is running at https://192.168.211.51:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
6.6 查看集群ip
$ minikube ip
192.168.211.51
6.7 查看插件
$ minikube addons list
|-----------------------------|----------|--------------|--------------------------------|
| ADDON NAME | PROFILE | STATUS | MAINTAINER |
|-----------------------------|----------|--------------|--------------------------------|
| ambassador | minikube | disabled | third-party (ambassador) |
| auto-pause | minikube | disabled | google |
| csi-hostpath-driver | minikube | disabled | kubernetes |
| dashboard | minikube | disabled | kubernetes |
| default-storageclass | minikube | enabled ✅ | kubernetes |
| efk | minikube | disabled | third-party (elastic) |
| freshpod | minikube | disabled | google |
| gcp-auth | minikube | disabled | google |
| gvisor | minikube | disabled | google |
| helm-tiller | minikube | disabled | third-party (helm) |
| ingress | minikube | disabled | unknown (third-party) |
| ingress-dns | minikube | disabled | google |
| istio | minikube | disabled | third-party (istio) |
| istio-provisioner | minikube | disabled | third-party (istio) |
| kong | minikube | disabled | third-party (Kong HQ) |
| kubevirt | minikube | disabled | third-party (kubevirt) |
| logviewer | minikube | disabled | unknown (third-party) |
| metallb | minikube | disabled | third-party (metallb) |
| metrics-server | minikube | disabled | kubernetes |
| nvidia-driver-installer | minikube | disabled | google |
| nvidia-gpu-device-plugin | minikube | disabled | third-party (nvidia) |
| olm | minikube | disabled | third-party (operator |
| | | | framework) |
| pod-security-policy | minikube | disabled | unknown (third-party) |
| portainer | minikube | disabled | portainer.io |
| registry | minikube | disabled | google |
| registry-aliases | minikube | disabled | unknown (third-party) |
| registry-creds | minikube | disabled | third-party (upmc enterprises) |
| storage-provisioner | minikube | enabled ✅ | google |
| storage-provisioner-gluster | minikube | disabled | unknown (third-party) |
| volumesnapshots | minikube | disabled | kubernetes |
|-----------------------------|----------|--------------|--------------------------------|
7. 常用操作
7.1 进入集群节点
minikube ssh
7.2 停止集群
minikube stop
7.3 启动集群
minikube start
7.4 删除集群
minikube delete
8. 部署 dashboard
Dashboard 是一个基于 Web 的 Kubernetes 用户界面。您可以使用它来:
- 将容器化应用程序部署到 Kubernetes 集群
- 对您的容器化应用程序进行故障排除
- 管理集群资源
- 概览在您的集群上运行的应用程序
- 创建或修改单个 Kubernetes 资源(例如 Deployment、Jobs、DaemonSets 等)
例如,您可以使用部署向导扩展部署、启动滚动更新、重新启动 pod 或部署新应用程序。
minikube dashboard
这将启用仪表板插件,并在默认 Web 浏览器中打开代理。
值得注意的是,Web 浏览器通常不能以 root 用户身份正常运行,因此如果您处于以 root 用户身份运行的环境中,请参阅仅 URL选项。
要停止代理(使仪表板保持运行),请中止已启动的进程 ( Ctrl+C
)。
#仅获取仪表板 URL
minikube dashboard --url
9. 部署 NGINX Ingress Controller
$ minikube addons enable ingress
- Using image registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.1.1
- Using image registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1
- Using image registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1
* Verifying ingress addon...
* 启动 'ingress' 插件
$ kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-admission-create-6hf47 0/1 Completed 0 91s
ingress-nginx-admission-patch-5dpqz 0/1 Completed 0 91s
ingress-nginx-controller-6cfb67d797-gqj98 1/1 Running 0 91s