minikube搭建简单的k8s环境

前记

其实本来是不想写的,今天想搞一下发现之前弄的全忘了- -好记性不如烂笔头啊!

安装步骤

安装kubectl

1
2
3
4
#下载最新<br>
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
#下载指定版本
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl

或者自己编译啥的爱咋样咋样

1
2
#移动到path下<br>
sudo mv ./kubectl /usr/local/bin/kubectl

测试下是否正常
kubectl version

安装minikube

  1. 去minikube的github页,找到他的Release下载对应版本
  2. 下载二进制包编译安装
    1
    2
    3
    4
    #下载<br>
    curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube<br>
    #安装<br>
    install minikube /usr/local/bin/

自行选择

安装k8s

先禁用下metrics-serverminikube addons disable metrics-server

1
2
3
4
5
minikube start \
--vm-driver=none \
--registry-mirror=https://registry.docker-cn.com \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers \
--extra-config=kubelet.authentication-token-webhook=true

extra-config是因为后面要装metrics-server

安装完后执行

1
kubectl get pods -A

查看下pods状态,如果coredns的状态异常的话

1
2
3
4
5
6
7
#!/bin/bash
systemctl stop kubelet
systemctl stop docker
iptables --flush
iptables -tnat --flush
systemctl start kubelet
systemctl start docker

这段脚本执行下应该就没啥问题了

开启dashboard

1
minikube dashboard --url

等待下,一般也是没啥问题,会显示dashboard的访问地址

复制地址到浏览器,改下ip,可能会发现…诶!访问不到!

好像是因为只监听本机的原因我也不是很懂,也有可能不是nodeport

1
kubectl proxy --port=8001 --address='192.168.113.55' --accept-hosts='^.*' &

用proxy把他映射出来,address改成你的,不知道就minikube ip看下

再访问就哦了

加上metrics-server

地址 自己去下载

里面也有教程,看不到的话就…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# disable the metrics-server addon for minikube in case it was enabled, because it installs the metric-server@v0.2.1
$ minikube addons disable metrics-server

# now start a new minikube
$ minikube delete; minikube start --extra-config=kubelet.authentication-token-webhook=true
🔥 Deleting "minikube" from virtualbox ...
💔 The "minikube" cluster has been deleted.
😄 minikube v1.2.0 on linux (amd64)
🔥 Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
🐳 Configuring environment for Kubernetes v1.15.0 on Docker 18.09.6
▪ kubelet.authentication-token-webhook=true
🚜 Pulling images ...
🚀 Launching Kubernetes ...
⌛ Verifying: apiserver proxy etcd scheduler controller dns
🏄 Done! kubectl is now configured to use "minikube"

# deploy the latest metric-server
$ kubectl create -f deploy/1.8+/
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
serviceaccount/metrics-server created
deployment.extensions/metrics-server created
service/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created

# edit metric-server deployment to add the flags
# args:
# - --kubelet-insecure-tls
# - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
$ kubectl edit deploy -n kube-system metrics-server

前面两部其实建k8s那都做了,其实只需要把那个服务起起来就好了

然后就好了,可以看到pod的一些监控?

end…