Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.
Kubernetes官网地址https://kubernetes.io/
但是,进入首页后依然会很懵逼,进入Documentation页面会更懵逼,对于初学者想依照文档搭建个环境try一下相当费劲,太乱了,下面我会整理下相关步骤以及文档地址。
kubernetes运行环境选择
官方说明:https://kubernetes.io/docs/setup/pick-right-solution/
Kubernetes can run on various platforms: from your laptop, to VMs on a cloud provider, to rack of bare metal servers. The effort required to set up a cluster varies from running a single command to crafting your own customized cluster. Use this guide to choose a solution that fits your needs.
- Local-machine Solutions
just want to “kick the tires” on Kubernetes - Hosted Solutions
ready to scale up to more machines and higher availability - Turnkey Cloud Solutions
you already have a way to configure hosting resources - Custom Solutions
这里我们选择最简单的Local-machine Solutions模式。
我是Mac环境,会以mac为主,单操作步骤也会说明其他环境如何安装。
在minikube上运行Local-machine Solutions模式
官网说明:https://kubernetes.io/docs/getting-started-guides/minikube/
官方说明会要求你先安装minikube,安装minikube说明在
https://kubernetes.io/docs/tasks/tools/install-minikube/,这里会要求先安装Hypervisor
安装Hypervisor
我选择的是OS X的第二个选项,VirtualBox,因为这个下载下来直接就是一个dmg文件,方便安装 VirtualBox-5.1.26-117224-OSX.dmg,94M。
安装后启动
红框内是因为我启动过本地的minikube,刚安装好时是没有的。
安装kubectl
官方说明:https://kubernetes.io/docs/tasks/tools/install-kubectl/
根据环境选择不同页签哦。
我选择macos命令行输入 curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.7.0/bin/darwin/amd64/kubectl
下载完成后,执行chmod +x ./kubectl,保证其执行权限
将包移动至类路径下
sudo mv ./kubectl /usr/local/bin/kubectl
到此,kubectl就安装完成了,这页官网剩下的内容可以忽略或简单看下即可了。
安装Minikube
现在才开始真正安装Minikube
地址:https://github.com/kubernetes/minikube/releases
Windows安装包在这一页也是可以找到的,往下翻即可。
我选择OSX
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.21.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
好了,minikube安装好了,需要的安装包基本都已ok啦。
现在可以开始配置了。
配置
依次执行如下5个步骤
bjjbgi-3-86:~ zhangxiaolong$ minikube start
Starting local Kubernetes v1.7.0 cluster...
Starting VM...
Downloading Minikube ISO
97.80 MB / 97.80 MB [==============================================] 100.00% 0s
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Starting cluster components...
Connecting to cluster...
Setting up kubeconfig...
Kubectl is now configured to use the cluster.
bjjbgi-3-86:~ zhangxiaolong$ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8082 deployment "hello-minikube" created
deployment "hello-minikube" created
bjjbgi-3-86:~ zhangxiaolong$ kubectl expose deployment hello-minikube --type=NodePort
service "hello-minikube" exposed
bjjbgi-3-86:~ zhangxiaolong$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-2853025882-5rr1t 0/1 ContainerCreating 0 1m
bjjbgi-3-86:~ zhangxiaolong$ curl $(minikub service hello-minikube --url)
-bash: minikub: command not found
curl: try 'curl --help' or 'curl --manual' for more information
bjjbgi-3-86:~ zhangxiaolong$ curl $(minikube service hello-minikube --url)
Waiting, endpoint for service is not ready yet...
Waiting, endpoint for service is not ready yet...
Waiting, endpoint for service is not ready yet...
Waiting, endpoint for service is not ready yet...
Waiting, endpoint for service is not ready yet...
^C
我的在第5步的时候,报了Waiting, endpoint for service is not ready yet.
试了几次都不行,官网上第5步成功如下图
到此,我的最后一步测试没通过,明天再看吧,你们可以试试。
时间转到2017年08月02日。
折腾了一天,算是有了点小进展,补充在这里。
昨天安装完minikube后就通过 curl $(minikube service hello-minikube –url)来测试发现 一直在waiting,其实这个hello-minikube根本没有起来。
可以通过命令kubectl get pod查看
bjjbgi-3-86:~ zhangxiaolong$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-2853025882-5rr1t 0/1 ContainerCreating 0 23h
可以看到这个服务的status是ContainerCreating,这个代表什么含义呢,表面意思是容器创建中,
我们可以通过kubectl describe pod命令查看详细信息
bjjbgi-3-86:~ zhangxiaolong$ kubectl describe pod
Name: hello-minikube-2853025882-5rr1t
Namespace: default
Node: minikube/192.168.99.100
Start Time: Tue, 01 Aug 2017 18:53:27 +0800
Labels: pod-template-hash=2853025882
run=hello-minikube
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"hello-minikube-2853025882","uid":"a5e87f14-76a7-11e7-a070-080027...
Status: Pending
IP: 172.17.0.3
Created By: ReplicaSet/hello-minikube-2853025882
Controlled By: ReplicaSet/hello-minikube-2853025882
Containers:
hello-minikube:
Container ID:
Image: gcr.io/google_containers/echoserver:1.4
Image ID:
Port: 8082/TCP
Args:
deployment
hello-minikube
created
State: Waiting
Reason: ErrImagePull
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-xxfxr (ro)
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-xxfxr:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-xxfxr
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
25m 25m 1 kubelet, minikube Normal SuccessfulMountVolume MountVolume.SetUp succeeded for volume "default-token-xxfxr"
23m 23m 1 kubelet, minikube spec.containers{hello-minikube} Warning Failed Failed to pull image "gcr.io/google_containers/echoserver:1.4": rpc error: code = 2 desc = Error response from daemon: {"message":"Get https://gcr.io/v1/_ping: dial tcp 64.233.189.82:443: i/o timeout"}
22m 20m 2 kubelet, minikube spec.containers{hello-minikube} Warning Failed Failed to pull image "gcr.io/google_containers/echoserver:1.4": rpc error: code = 2 desc = Error response from daemon: {"message":"Get https://gcr.io/v1/_ping: dial tcp 64.233.187.82:443: i/o timeout"}
16m 16m 1 kubelet, minikube spec.containers{hello-minikube} Warning Failed Failed to pull image "gcr.io/google_containers/echoserver:1.4": rpc error: code = 2 desc = Error response from daemon: {"message":"Get https://gcr.io/v2/google_containers/echoserver/manifests/1.4: Get https://gcr.io/v2/token?scope=repository%3Agoogle_containers%2Fechoserver%3Apull\u0026service=gcr.io: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"}
19m 13m 2 kubelet, minikube spec.containers{hello-minikube} Warning Failed Failed to pull image "gcr.io/google_containers/echoserver:1.4": rpc error: code = 2 desc = Error response from daemon: {"message":"Get https://gcr.io/v1/_ping: dial tcp 74.125.203.82:443: i/o timeout"}
23m 8m 42 kubelet, minikube spec.containers{hello-minikube} Normal BackOff Back-off pulling image "gcr.io/google_containers/echoserver:1.4"
23m 8m 48 kubelet, minikube Warning FailedSync Error syncing pod
25m 7m 7 kubelet, minikube spec.containers{hello-minikube} Normal Pulling pulling image "gcr.io/google_containers/echoserver:1.4"
1m 1m 1 kubelet, minikube Normal SuccessfulMountVolume MountVolume.SetUp succeeded for volume "default-token-xxfxr"
1m 1m 1 kubelet, minikube spec.containers{hello-minikube} Normal Pulling pulling image "gcr.io/google_containers/echoserver:1.4"
3s 3s 1 kubelet, minikube spec.containers{hello-minikube} Warning Failed Failed to pull image "gcr.io/google_containers/echoserver:1.4": rpc error: code = 2 desc = Error response from daemon: {"message":"Get https://gcr.io/v1/_ping: dial tcp 64.233.189.82:443: i/o timeout"}
3s 1s 2 kubelet, minikube Warning FailedSync Error syncing pod
1s 1s 1 kubelet, minikube spec.containers{hello-minikube} Normal BackOff Back-off pulling image "gcr.io/google_containers/echoserver:1.4"
相信你看到了Failed Failed to pull image “gcr.io/google_containers/echoserver:1.4”这行信息。
网上搜了一圈的资料,是因为gcr.io这个外国网站,我们访问不到。
OMG!!
所以出现了一些方案
1 用VPN,翻墙出去
2 使用国内镜像,推荐使用阿里云的
可以参考http://www.jianshu.com/p/a42eeb66a19c
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
作者:scipio
链接:http://www.jianshu.com/p/a42eeb66a19c
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
3 搭建自己的docker镜像仓库,将echoserver从国内镜像中pull下来,然后推送到自己的仓库上去,然后
minikube start kubectl run hello-minikube –image=registry.cn-hangzhou.aliyuncs.com/google-container/echoserver:1.4 –port=8080
这一步骤替换成自己的–image。
我选择了最惨的第3条路。
首先搭建本地docker镜像仓库,参见这里吧http://blog.csdn.net/MrZhangXL/article/details/76598932。
push到自己的仓库上去后,然后开始来做。
jjbgi-3-86:~ zhangxiaolong$ kubectl run hellox-minikube --image=10.20.2.127:5000/echoserver --port=8082
deployment "hellox-minikube" created
bjjbgi-3-86:~ zhangxiaolong$ kubectl expose deployment hellox-minikube --type=NodePort
service "hellox-minikube" exposed
bjjbgi-3-86:~ zhangxiaolong$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hellox-minikube-1229068855-2g7qv 0/1 ImagePullBackOff 0 1m
还是不行,还是ImagePullBackOff状态。
再通过 kubectl describe pod命令看看详细信息
/var/run/secrets/kubernetes.io/serviceaccount from default-token-xxfxr (ro)
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-xxfxr:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-xxfxr
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
2m 2m 1 default-scheduler Normal ScheduleSuccessfully assigned hellox-minikube-1229068855-2g7qv to minikube
2m 2m 1 kubelet, minikube Normal SuccessfulMountVolume MountVolume.SetUp succeeded for volume "default-token-xxfxr"
1m 1m 1 kubelet, minikube spec.containers{hellox-minikube} Normal BackOff Back-off pulling image "10.20.2.127:5000/echoserver"
2m 1m 2 kubelet, minikube spec.containers{hellox-minikube} Normal Pulling pulling image "10.20.2.127:5000/echoserver"
1m 7s 2 kubelet, minikube spec.containers{hellox-minikube} Warning Failed Failed to pull image "10.20.2.127:5000/echoserver": rpc error: code = 2 desc = Error response from daemon: {"message":"Get https://10.20.2.127:5000/v1/_ping: http: server gave HTTP response to HTTPS client"}
1m 7s 3 kubelet, minikube Warning FailedSync Error syncing pod
仿佛换了个错误,http: server gave HTTP response to HTTPS client,这个错误原因是因为给了https请求的http响应,应该改我镜像仓库机器没有配置https证书。
搜索解决方案是:
启动minikube时增加参数–insecure-registry
jjbgi-3-86:~ zhangxiaolong$ minikube delete
Deleting local Kubernetes cluster...
Machine deleted.
bjjbgi-3-86:~ zhangxiaolong$ minikube start --vm-driver=virtualbox --insecure-registry=10.20.2.127:5000
Starting local Kubernetes v1.7.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Starting cluster components...
Connecting to cluster...
Setting up kubeconfig...
接着启服务
jjbgi-3-86:~ zhangxiaolong$ kubectl run hellox-minikube --image=10.20.2.127:5000/echoserver --port=8082
deployment "hellox-minikube" created
bjjbgi-3-86:~ zhangxiaolong$ kubectl expose deployment hellox-minikube --type=NodePort
service "hellox-minikube" exposed
bjjbgi-3-86:~ zhangxiaolong$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hellox-minikube-1229068855-p5ls6 0/1 ContainerCreating 0 55s
还是ContainerCreating状态,要崩溃了。
继续kubectl describe hellox-minikube-1229068855-p5ls6命令看看详细信息
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-gxqn0 (ro)
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-gxqn0:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-gxqn0
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
1m 1m 1 default-scheduler Normal Scheduled Successfully assigned hellox-minikube-1229068855-p5ls6 to minikube
1m 1m 1 kubelet, minikube Normal SuccessfulMountVolume MountVolume.SetUp succeeded for volume "default-token-gxqn0"
49s 49s 1 kubelet, minikube Warning FailedSync Error syncing pod
好像并没有什么错误啊,只有这个Error syncing pod
网上搜了一圈,也没有答案,最后还是在http://www.jianshu.com/p/a42eeb66a19c这篇文章中看到了一些猫腻
他的报错信息,是这样子的
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\""
作者:scipio
链接:http://www.jianshu.com/p/a42eeb66a19c
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
他有details,这太完美了,难道我的是没有details,原因和其一样么?
抱着试试看的心态,使用了他的解决方案:
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
作者:scipio
链接:http://www.jianshu.com/p/a42eeb66a19c
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
执行完毕后 通过exit命令退出ssh交互。
此时,再看看pod状态
bjjbgi-3-86:~ zhangxiaolong$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hellox-minikube-1229068855-7j2n2 1/1 Running 1 30m
居然运行起来了,哈哈哈哈哈。。。
bjjbgi-3-86:~ zhangxiaolong$ minikube dashboard
Opening kubernetes dashboard in default browser...