序
上次虽然写了两篇在mac装kubernetes的,但是仅仅限于初步安装,这次再补上跑个demo,正好也赶上阿里云有相关镜像,于是这里再次记录下。
安装minikube
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.15.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
安装kubectl
curl -Lo kubectl http://storage.googleapis.com/kubernetes-release/release/v1.5.1/bin/darwin/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
启动
minikube startkubectl run hello-minikube --image=registry.cn-hangzhou.aliyuncs.com/google-container/echoserver:1.4 --port=8080kubectl expose deployment hello-minikube --type=NodePortkubectl get pod
问题
pod的status都在ContainerCreating,查看
kubectl describe pods
出错部分log
Events: FirstSeen LastSeen Count From SubobjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 8m 8m 1 {default-scheduler } Normal Scheduled Successfully assigned hello-minikube-957602326-t9mzf to minikube 6m 3m 2 {kubelet minikube} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for gcr.io/google_containers/pause-amd64:3.0, this may be because there are no credentials on this request. details: (Error response from daemon: Get https://gcr.io/v1/_ping: dial tcp 64.233.187.82:443: i/o timeout)" 6m 1m 10 {kubelet minikube} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"gcr.io/google_containers/pause-amd64:3.0\""
解决问题
参考这篇文章的方法,这里我们用阿里的镜像
minikube sshdocker pull registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0
删除pod再观察下
kubectl delete pods xxxxkubectl get pod --all-namespaces
这下变成running了
NAME READY STATUS RESTARTS AGEhello-minikube-957602326-gf17s 1/1 Running 0 40s
跑下demo
curl $(minikube service hello-minikube --url)
输出
CLIENT VALUES:client_address=172.17.0.1command=GETreal path=/query=nilrequest_version=1.1request_uri=http://192.168.99.101:8080/SERVER VALUES:server_version=nginx: 1.10.0 - lua: 10001HEADERS RECEIVED:accept=*/*host=192.168.99.101:31860user-agent=curl/7.43.0BODY:
解决kube-addon-manager-minikube的ImagePullBackOff问题
查看详情
kubectl describe --namespace=kube-system po kube-addon-manager-minikube
发现拉取gcr.io/google-containers/kube-addon-manager:v6.1失败,使用阿里云的镜像fix一下
minikube sshdocker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kube-addon-manager-amd64:v6.1docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/kube-addon-manager-amd64:v6.1 gcr.io/google-containers/kube-addon-manager:v6.1
使用
kubectl get pods --all-namespaces
正常了
NAMESPACE NAME READY STATUS RESTARTS AGEdefault hello-minikube-957602326-gf17s 1/1 Running 1 44mkube-system kube-addon-manager-minikube 1/1 Running 0 55m
minikube dashboard
kubectl get pod --all-namespacesNAMESPACE NAME READY STATUS RESTARTS AGEdefault hello-minikube-957602326-gf17s 1/1 Running 1 47mkube-system kube-addon-manager-minikube 1/1 Running 0 58mkube-system kube-dns-v20-m9p7t 0/3 ContainerCreating 0 2mkube-system kubernetes-dashboard-k6z7w 0/1 ImagePullBackOff 0 2m
查看下
kubectl describe --namespace=kube-system po kube-dns-v20-m9p7t
fix
minikube sshdocker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kubedns-amd64:1.9docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/kubedns-amd64:1.9 gcr.io/google_containers/kubedns-amd64:1.9docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kube-dnsmasq-amd64:1.4docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/kube-dnsmasq-amd64:1.4 gcr.io/google_containers/kube-dnsmasq-amd64:1.4docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/exechealthz-amd64:1.2docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/exechealthz-amd64:1.2 gcr.io/google_containers/exechealthz-amd64:1.2
fix
kubectl describe --namespace=kube-system po kubernetes-dashboard-k6z7wdocker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kubernetes-dashboard-amd64:v1.5.0docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/kubernetes-dashboard-amd64:v1.5.0 gcr.io/google_containers/kubernetes-dashboard-amd64:v1.5.1
最后再次打开dashboard
minikube dashboard
看到久违的界面了