序
上次虽然写了两篇在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 start
kubectl run hello-minikube --image=registry.cn-hangzhou.aliyuncs.com/google-container/echoserver:1.4 --port=8080
kubectl expose deployment hello-minikube --type=NodePort
kubectl 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\""
解决问题
参考k8s初游: minikube启动docker镜像这篇文章的方法,这里我们用阿里的镜像
minikube ssh
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0
docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0
删除pod再观察下
kubectl delete pods xxxx
kubectl get pod --all-namespaces
这下变成running了
NAME READY STATUS RESTARTS AGE
hello-minikube-957602326-gf17s 1/1 Running 0 40s
跑下demo
curl $(minikube service hello-minikube --url)
输出
CLIENT VALUES:
client_address=172.17.0.1
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://192.168.99.101:8080/
SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001
HEADERS RECEIVED:
accept=*/*
host=192.168.99.101:31860
user-agent=curl/7.43.0
BODY:
解决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 ssh
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kube-addon-manager-amd64:v6.1
docker 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 AGE
default hello-minikube-957602326-gf17s 1/1 Running 1 44m
kube-system kube-addon-manager-minikube 1/1 Running 0 55m
minikube dashboard
kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default hello-minikube-957602326-gf17s 1/1 Running 1 47m
kube-system kube-addon-manager-minikube 1/1 Running 0 58m
kube-system kube-dns-v20-m9p7t 0/3 ContainerCreating 0 2m
kube-system kubernetes-dashboard-k6z7w 0/1 ImagePullBackOff 0 2m
查看下
kubectl describe --namespace=kube-system po kube-dns-v20-m9p7t
fix
minikube ssh
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kubedns-amd64:1.9
docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/kubedns-amd64:1.9 gcr.io/google_containers/kubedns-amd64:1.9
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kube-dnsmasq-amd64:1.4
docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/kube-dnsmasq-amd64:1.4 gcr.io/google_containers/kube-dnsmasq-amd64:1.4
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/exechealthz-amd64:1.2
docker 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-k6z7w
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kubernetes-dashboard-amd64:v1.5.0
docker 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
看到久违的界面了
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。