安装 kubeadm、kubelet 和 kubectl
此步骤可选
下载 kubeadm
# wget -P /usr/local/bin https://dl.k8s.io/release/v1.28.3/bin/linux/amd64/kubeadm
下载 kubelet
# wget -P /usr/local/bin https://dl.k8s.io/release/v1.28.3/bin/linux/amd64/kubelet
下载 kubectl
# wget -P /usr/local/bin https://dl.k8s.io/release/v1.28.3/bin/linux/amd64/kubectl
添加执行权限
# chmod +x /usr/local/bin/kube*
kubectl 命令补全
apt install -y bash-completion
kubectl completion bash > /etc/profile.d/kubectl_completion.sh
. /etc/profile.d/kubectl_completion.sh
加速 minikube 下载 kubeadm、kubelet 和 kubectl
创建 minikube 工作目录
此目录会自动创建,本次手动创建是因为手动下载kubectl、kubeadm、kubelet,提速minikube的下载。
# mkdir /root/.minikube/cache/linux/amd64/v1.28.3 -pv
复制 kubeadm、kubelet 和 kubectl 到指定目录
# cp /usr/local/bin/kube* /root/.minikube/cache/linux/amd64/v1.28.3/
minikube 创建 k8s 集群
# minikube start -p c1 --kubernetes-version=v1.28.3 --listen-address="0.0.0.0" --apiserver-ips=192.168.174.117,192.168.174.118,192.168.174.119 --image-mirror-country='cn' --registry-mirror=https://0961b8c584000f7f0fd6c0041a439240.mirror.swr.myhuaweicloud.com --base-image=registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.42 --driver=docker --container-runtime=docker --cpus=2 --memory=2200m --disk-size=20000mb --force
* [c1] minikube v1.32.0 on Ubuntu 23.10
! minikube skips various validations when --force is supplied; this may lead to unexpected behavior
* Using the docker driver based on user configuration
* 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/
* Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
* Using Docker driver with root privileges
* Starting control plane node c1 in cluster c1
* Pulling base image ...
* Creating docker container (CPUs=2, Memory=2200MB) ...
* minikube is not meant for production use. You are opening non-local traffic
! Listening to 0.0.0.0. This is not recommended and can cause a security vulnerability. Use at your own risk
! This container is having trouble accessing https://registry.cn-hangzhou.aliyuncs.com/google_containers
* To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
* Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
- Generating certificates and keys ...
- Booting up control plane ...
- Configuring RBAC rules ...
* Configuring bridge CNI (Container Networking Interface) ...
- Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
* Verifying Kubernetes components...
* Enabled addons: storage-provisioner, default-storageclass
* Done! kubectl is now configured to use "c1" cluster and "default" namespace by default
minikube dashboard
启用 dashboard
# minikube dashboard -p c1
* Enabling dashboard ...
- Using image docker.io/kubernetesui/dashboard:v2.7.0
- Using image docker.io/kubernetesui/metrics-scraper:v1.0.8
* Some dashboard features require the metrics-server addon. To enable all features please run:
minikube -p c1 addons enable metrics-server
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
http://127.0.0.1:26327/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
远程访问 dashboard 端口
# kubectl proxy --address 0.0.0.0 -p 9080 --accept-hosts='^*$'
Starting to serve on [::]:9080
远程访问 dashboard
特别说明:
宿主机IP:192.168.174.120
http://192.168.174.120:9080/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/workloads?namespace=default
minikube 集群信息
查看集群列表
# minikube profile list
|---------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|---------|-----------|---------|--------------|------|---------|---------|-------|--------|
| c1 | docker | docker | 192.168.49.2 | 8443 | v1.28.3 | Running | 1 | |
|---------|-----------|---------|--------------|------|---------|---------|-------|--------|
查看集群状态
# minikube status -p c1
c1
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
查看 img
# minikube image ls --format table
|-----------------------------------------------------------------------------|---------|---------------|--------|
| Image | Tag | Image ID | Size |
|-----------------------------------------------------------------------------|---------|---------------|--------|
| docker.io/kubernetesui/metrics-scraper | <none> | 115053965e86b | 43.8MB |
| registry.cn-hangzhou.aliyuncs.com/google_containers/coredns | v1.10.1 | ead0a4a53df89 | 53.6MB |
| docker.io/kubernetesui/dashboard | <none> | 07655ddf2eebe | 246MB |
| registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager | v1.28.3 | 10baa1ca17068 | 122MB |
| registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy | v1.28.3 | bfc896cf80fba | 73.1MB |
| registry.cn-hangzhou.aliyuncs.com/google_containers/etcd | 3.5.9-0 | 73deb9a3f7025 | 294MB |
| registry.cn-hangzhou.aliyuncs.com/google_containers/pause | 3.9 | e6f1816883972 | 744kB |
| registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner | v5 | 6e38f40d628db | 31.5MB |
| registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver | v1.28.3 | 5374347291230 | 126MB |
| registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler | v1.28.3 | 6d1b4fd1b182d | 60.1MB |
|-----------------------------------------------------------------------------|---------|---------------|--------|
查看 pod 信息
# kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-6554b8b87f-phjfx 1/1 Running 0 6m1s
kube-system etcd-minikube 1/1 Running 0 6m14s
kube-system kube-apiserver-minikube 1/1 Running 0 6m16s
kube-system kube-controller-manager-minikube 1/1 Running 0 6m14s
kube-system kube-proxy-qpt77 1/1 Running 0 6m2s
kube-system kube-scheduler-minikube 1/1 Running 0 6m15s
kube-system storage-provisioner 1/1 Running 0 6m13s
kubernetes-dashboard dashboard-metrics-scraper-7fd5cb4ddc-xxk4r 1/1 Running 0 4m1s
kubernetes-dashboard kubernetes-dashboard-8694d4445c-j5b5t 1/1 Running 0 4m1s
部署应用
创建 ns
# kubectl create ns nginx-demo
namespace/nginx-demo created
部署 nginx
# kubectl create deployment nginx --image=nginx:1.24-alpine -n nginx-demo
deployment.apps/nginx created
创建 svc
# kubectl create svc nodeport nginx --tcp=80:80 -n nginx-demo
service/nginx created
查看 pod
# kubectl get pods -n nginx-demo -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-6686c79596-hw747 1/1 Running 0 35s 10.244.0.9 minikube <none> <none>
查看 svc
# kubectl get svc -n nginx-demo -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
nginx NodePort 10.110.176.151 <none> 80:30960/TCP 62s app=nginx
部署 client
# kubectl run client --image=ikubernetes/admin-box -it --rm --restart=Never --command -n default -- /bin/bash
通过 IP 访问 nginx
# curl 10.244.0.9 -I
HTTP/1.1 200 OK
Server: nginx/1.24.0
Date: Fri, 22 Dec 2023 06:28:17 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 11 Apr 2023 17:21:57 GMT
Connection: keep-alive
ETag: "64359735-267"
Accept-Ranges: bytes
通过 svc 访问 nginx
# curl nginx.nginx-demo.svc.cluster.local -I
HTTP/1.1 200 OK
Server: nginx/1.24.0
Date: Fri, 22 Dec 2023 06:41:51 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 11 Apr 2023 17:21:57 GMT
Connection: keep-alive
ETag: "64359735-267"
Accept-Ranges: bytes
通过宿主机访问 nginx
登录 minikube 集群
# minikube ssh -p c1
docker@minikube:~$
访问 nginx
docker@minikube:~$ curl 127.0.0.1:30960 -I
HTTP/1.1 200 OK
Server: nginx/1.24.0
Date: Fri, 22 Dec 2023 06:44:58 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 11 Apr 2023 17:21:57 GMT
Connection: keep-alive
ETag: "64359735-267"
Accept-Ranges: bytes
参考文档
https://github.com/kubernetes/minikube/blob/master/deploy/addons/aliyun_mirror.json
标签:kubectl,kube,--,nginx,dashboard,minikube,v1.28,k8s From: https://www.cnblogs.com/wangguishe/p/17919094.html