k8s部署laravel应用

2019-03-13  本文已影响0人  莫轩然
FROM composer:1.6.5 as build 
WORKDIR /app 
COPY . /app 
RUN composer install

FROM php:7.1.8-apache 
EXPOSE 80 
COPY --from=build /app /app 
COPY vhost.conf /etc/apache2/sites-available/000-default.conf 
RUN chown -R www-data:www-data /app \ 
  && a2enmod rewrite
cd /path/to/your/project
<VirtualHost *:80>
  DocumentRoot /app/public

  <Directory "/app/public">
    AllowOverride all
    Require all granted
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
docker build -t yourname/laravel-kubernetes-demo .
docker run -ti -p 8080:80 -e APP_KEY=base64:cUPmwHx4LXa4Z25HhzFiWCf7TlQmSqnt98pnuiHmzgY=  laravel-kubernetes-demo

示例程序可以通过 http://localhost:8080 访问。
在这个安装中,容器是通用的,同时 APP_KEY 并不是写死或共享的。
页面可以正常访问,但数据库连接不上,报错数据库驱动找不到。

进入容器:
docker exec -ti 容器Id  bash
查看php扩展
php -m (发现php扩展中缺少pdo_mysql扩展)
安装pdo_mysql扩展
docker-php-ext-install pdo pdo_mysql
安装成功后退出容器并停止容器
docker run -d -p 5000:5000 --restart=always  registry:2
docker commit -m "提交内容"  容器id imageName:Version
docker tag yourname/laravel-k8s 127.0.0.1:5000/laravel-k8s
docker push 127.0.0.1:5000/laravle-k8s
docker rmi 旧镜像
FROM composer:1.6.5 as build
WORKDIR /app
COPY . /app
RUN composer install

FROM 127.0.0.1:5000/laravle-k8s
# 暴露 80 端口
EXPOSE 80
docker build -t yourname/laravel-k8s .
docker run -ti -p 8080:80 -e APP_KEY=base64:cUPmwHx4LXa4Z25HhzFiWCf7TlQmSqnt98pnuiHmzgY=  yourname/laravel-k8s
kubectl run laravel-k8s  --image=yourname/laravel-k8s  --port=80  --image-pull-policy=IfNotPresent  --env=APP_KEY=base64:cUPmwHx4LXa4Z25HhzFiWCf7TlQmSqnt98pnuiHmzgY=
开放服务端口
kubectl expose deployment laravel-yxd  --type=NodePort --port=80
kubectl proxy
上一篇下一篇

猜你喜欢

热点阅读