Kubernetes 实战教学,手把手教您运行第一个 Nginx 集群,


screenshot

出品丨Docker公司(ID:docker-cn)
编译丨小东
每周一、三、五,与您不见不散!


Nginx(发音为“engine-x”)是用于 HTTP、HTTPS、SMTP、POP3 和 IMAP 协议的开源反向代理服务器,以及负载均衡器、HTTP 缓存和 Web 服务器(源服务器)。Nginx 项目着眼于高并发性、高性能和低内存使用率。它是在类似 BSD 的2个条款许可证下授权的,可以在Linux、BSD变体、Mac OS X、Solaris、AIX、HP-UX 以及其他 *nix 版本上运行。它还为 Microsoft Windows 提供了概念验证端口。

在我的上一篇文章《Kubernetes 实战教学,手把手教您设置拥有5个节点的 K8S 群集》中,我展示了如何构建5个节点的 Kubernetes 集群。在本文中,我们将了解如何在这个集群环境中构建第一个 Nginx 应用程序。


验证5个节点 K8s 集群

[node1 ~]$ kubectl get nodes
NAME     STATUS   ROLES    AGE      VERSION
node1    Ready    master   1h       v1.10.2
node2    Ready       1h       v1.10.2
node3    Ready       1h       v1.10.2
node4    Ready       1h       v1.10.2
node5    Ready       14m      v1.10.2
[node1 ~]$

运行具有4个副本的 Nginx 应用

kubectl run nginx --image=nginx:latest --replicas=4

验证 K8s Pods 正常运行

[node1 ~]$ kubectl get po
NAME                    READY    STATUS   RESTARTS  AGE
nginx-5db977d67c-6sdfd  1/1      Running  0         2m
nginx-5db977d67c-jfq9h  1/1      Running  0         2m
nginx-5db977d67c-vs925  1/1      Running  0         2m
nginx-5db977d67c-z5r45  1/1      Running  0         2m
[node1 ~]$

查看 pods

kubectl get pods -w

公开 NGINX API 端口

kubectl expose deploy/nginx --port 80

测试 Nginx 服务

IP=$(kubectl get svc nginx -o go-template --template '{{ .spec.clusterIP }}')

发送请求

[node1 ~]$ curl $IP:80
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
 
For online documentation and support please refer to
<a href="http://nginx.org/nginx.org.
Commercial support is available at
<a href="http://nginx.com/nginx.com.
 
Thank you for using nginx.
[node1 ~]$

在下一篇博文中,我将展示如何在 Play with Kubernetes 平台上构建 Istio 应用程序。

相关内容