基于docker-compose yml 在 docker ma

2018-12-14  本文已影响0人  精灵GG

本文主要是结合官方的说明,简单介绍在docker的mac版本中,如何在kubernetes(k8s)中部署LNMP(PHP)环境。 在docker for mac 17.12 CE Edge 或者更加高的版本,现在是18.09.0版本,内置了Kubernetes,目前来说,Kubernetes 最新版本是1.10.3,如下图。

image.png

切换到docker-for-desktop环境中

查看当然环境
# kubectl config get-contexts  
或者
# kubectl get nodes
分别显示以下内容
CURRENT   NAME                 CLUSTER                      AUTHINFO             NAMESPACE
*         docker-for-desktop   docker-for-desktop-cluster   docker-for-desktop 
NAME                 STATUS    ROLES     AGE       VERSION
docker-for-desktop   Ready     master    1d        v1.10.3
若是在别的环境,用以下语句切换到docker-for-desktop环境中
# kubectl config use-context docker-for-desktop

使用docker命令来部署docker-compose.yml文件

# docker stack deploy --compose-file /path/to/docker-compose.yml mystack
查看部署了的服务
# docker stack services mystack
出现以下内容
ID                  NAME                MODE                REPLICAS            IMAGE                                                           PORTS
b20a5b42-ff4        mystack_mysql       replicated          1/1                 mysql:5.7                                                       *:3306->3306/tcp
b21092dc-ff4        mystack_nginx       replicated          1/1                 nginx:latest                                                    *:80->80/tcp, *:8100->8100/tcp, *:9100-9101->9100-9101/tcp
b217adc3-ff4        mystack_node        replicated          1/1                 registry.cn-shenzhen.aliyuncs.com/yxw-docker/node8.9.3:latest   *:7001->7001/tcp
b235cd6a-ff4        mystack_redis       replicated          1/1                 redis:3                                                         *:6379->6379/tcp
b23c3aea-ff4        mystack_fpm         replicated          1/1                 registry.cn-shenzhen.aliyuncs.com/yxw-docker/php7.1

kubectl命令查看部署的情况

部署情况
# kubectl get deploy
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
fpm       1         1         1            1           3m
mysql     1         1         1            1           3m
nginx     1         1         1            1           3m
node      1         1         1            1           3m
redis     1         1         1            1           3m
服务情况
# kubectl get svc
fpm                ClusterIP      None            <none>        55555/TCP                                                   6m
fpm-random-ports   NodePort       10.98.227.9     <none>        9000:32245/TCP                                              6m
kubernetes         ClusterIP      10.96.0.1       <none>        443/TCP                                                     1d
mysql              ClusterIP      None            <none>        55555/TCP                                                   6m
mysql-published    LoadBalancer   10.98.226.105   localhost     3306:31797/TCP                                              6m
nginx              ClusterIP      None            <none>        55555/TCP                                                   6m
nginx-published    LoadBalancer   10.97.226.184   localhost     80:30075/TCP,9100:30111/TCP,9101:30970/TCP,8100:30239/TCP   6m
node               ClusterIP      None            <none>        55555/TCP                                                   6m
node-published     LoadBalancer   10.106.195.88   localhost     7001:31570/TCP                                              6m
redis              ClusterIP      None            <none>        55555/TCP                                                   6m
redis-published    LoadBalancer   10.98.76.40     localhost     6379:32722/TCP                                              6m
pods的情况
# kubectl get pods
NAME                     READY     STATUS    RESTARTS   AGE
fpm-6d5d7865cb-m45wb     1/1       Running   0          9m
mysql-7ddd6996fb-8kgms   1/1       Running   0          9m
nginx-6f6f9b94bb-q59lm   1/1       Running   0          9m
node-6544849889-tf4kp    1/1       Running   0          9m
redis-5864f8c5cc-wh7ls   1/1       Running   0          9m

删除部署的内容

# docker stack rm mystack
上一篇下一篇

猜你喜欢

热点阅读