使用Gardener在Google Cloud Platform上创建Kubernetes集群

Gardener是一个开源项目,github地址:

https://github.com/gardener/gardener/

使用Gardener,我们可以在几分钟之内在GCP, AWS, Azure或者Openstack上轻松创建Kubernetes Cluster。

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

点击新建按钮创建一个Cluster,这里Infrastructure我选择的是gcp:

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

创建成功后,状态变为Ready,表明该集群已经可用了。

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

点击集群名称jerrycls,进入集群明细页面,在Access标签页下面获得这个集群的用户名admin和密码。

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

点击dashboard超链接,会弹出输入用户米和密码的提示。用户名输入admin,密码从上面Access标签页获取。即可进入集群的管理页面。从左下角处查看这个集群的三个namespace:default,kube-public和kube-system:

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

这是Gardener自动为我分配的工作节点:

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

点击kubeconfig,获得这个集群的config yaml文件,把它的内容复制下来:

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

我使用的操作系统是ubuntu,上面安装了kubectl.

进入目录/home/vagrant/.kube, 用vi编辑config文件:

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

把从Gardener里拷贝的内容粘贴到config文件里。

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

现在使用kubectl get ns,就可以看到Kubernetes cluster上的三个namespace,和我们前面在dashboard里观察到的一致。

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

使用kubectl get node -o wide, 看到一个工作节点,和之前在Kubernetes dashboard里观察到的一致。

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

使用命令kubectl run nginx –image=nginx:1.12.2创建一个deployment,运行nginx container:

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

创建好deployment之后,使用命令行创建一个service,把nginx服务暴露给外部:

kubectl expose deployment nginx –type=loadBalancer –port=80 –target-port=80

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

使用kubectl get svc查看生成的service,供外部访问的IP地址从EXTERNAL-IP处获得:35.233.45.209:

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

在浏览器里直接访问这个ip地址,看到nginx默认的首页,说明部署在Google Cloud Platform上的Kubernetes cluster能够正常工作了。

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

要获取更多Jerry的原创文章,请关注公众号”汪子熙”:

《使用Gardener在Google Cloud Platform上创建Kubernetes集群》

    原文作者:JerryWangSAP
    原文地址: https://segmentfault.com/a/1190000017116689
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞