您好,登錄后才能下訂單哦!
本篇文章為大家展示了PHP環(huán)境中如何使用k8s集群,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
wget https://cn.wordpress.org/latest-zh_CN.zip復(fù)制代碼
create database wordpress DEFAULT CHARACTER SET utf8; grant all on wordpress.* to 'wordpress'@'%' identified by '123456';復(fù)制代碼
mkdir /data -p mount -t nfs -o vers=4,minorversion=0,noresvport 12XXXXXXXxx.cn-hongkong.nas.aliyuncs.com:/ /data mv wordpress /data/復(fù)制代碼
mkdir -p Dockerfile [root@k8s-m Dockerfile]# cat default.conf server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { root /var/www/html; fastcgi_pass php-svc.default.svc.cluster.local:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } [root@k8s-m Dockerfile]# cat Dockerfile FROM nginx:1.15.4-alpine LABEL maintainer="zhang 1232@qq.com"COPY default.conf /etc/nginx/conf.d/ EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]#構(gòu)建鏡像(沒有鏡像倉庫的話,要把鏡像導(dǎo)入到其它服務(wù)器上)[root@k8s-m Dockerfile]# docker build -t mynginx:2.0 ./#查看鏡像[root@k8s-m Dockerfile]# docker images|grep mynginxmynginx 2.0 2fd9a2724422 2 hours ago 17.7MB復(fù)制代碼
[root@k8s-m ~]# cat php.yamlapiVersion: v1 kind: Service metadata: name: php-svc spec: selector: name: php ports: - port: 9000 name: http-php targetPort: 9000 protocol: TCP --- apiVersion: apps/v1 kind: Deployment metadata: name: my-php-deploy spec: replicas: 3 selector: matchLabels: name: php template: metadata: labels: name: php spec: containers: - name: php image: php:7.2-fpm ports: - name: http-php containerPort: 9000 volumeMounts: - name: php-code mountPath: /var/www/html/ volumes: - name: php-code nfs: path: /wordpress/ server: 12xxxxxxxxx.cn-hongkong.nas.aliyuncs.com復(fù)制代碼
[root@k8s-m ~]# cat nginx-deploy.yamlapiVersion: v1 kind: Service metadata: name: nginx-svc spec: selector: name: nginx ports: - port: 80 name: http targetPort: 80 protocol: TCP --- apiVersion: apps/v1 kind: Deployment metadata: name: my-nginx-deploy spec: replicas: 3 selector: matchLabels: name: nginx template: metadata: labels: name: nginx spec: containers: - name: nginx image: mynginx:2.0 imagePullPolicy: IfNotPresent ports: - name: http containerPort: 80 volumeMounts: - name: html mountPath: /usr/share/nginx/html/ volumes: - name: html nfs: path: /wordpress/ server: 124xxxxxxxxxxxxx-hongkong.nas.aliyuncs.com復(fù)制代碼
[root@k8s-m ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 none 443/TCP 4h25m nginx-svc ClusterIP 10.101.81.167 none 80/TCP 99m php-svc ClusterIP 10.111.89.228 none 9000/TCP 99m [root@k8s-m ~]# kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE my-nginx-deploy 3/3 3 3 99m my-php-deploy 3/3 3 3 100m復(fù)制代碼
[root@k8s-m ~]# cat wordpress-ingress.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-nginx spec: rules: - host: haha.zhang.com http: paths: - backend: serviceName: nginx-svc servicePort: 80 [root@k8s-m ~]# kubectl apply -f wordpress-ingress.yaml ingress.extensions/ingress-nginx created復(fù)制代碼
php容器中的ini擴(kuò)展文件路徑:/usr/local/etc/php/conf.d/
[root@node1 ~]# docker run -it --name php-gd php:7.2-fpm bash復(fù)制代碼
apt-get update && apt-get install libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng-dev -y復(fù)制代碼
docker-php-ext-configure gd#安裝docker-php-ext-install gd#啟用docker-php-ext-enable gd復(fù)制代碼
[root@node1 ~]# docker commit -p php-gd php-gd:1.0sha256:c562ad539630b3c5eb6888f0b7bac937d9d3af1d39de118106c5e6ca30a02ebd [root@node1 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE php-gd 1.0 c562ad539630 4 seconds ago 426MB復(fù)制代碼
[root@node1 ~]# docker run -it --rm php-gd:1.0 bash root@9e7fa8e57db7:/var/www/html# ls /usr/local/etc/php/conf.d/docker-php-ext-gd.ini /usr/local/etc/php/conf.d/docker-php-ext-gd.ini root@9e7fa8e57db7:/var/www/html# cat /usr/local/etc/php/conf.d/docker-php-ext-gd.ini extension=gd.so root@9e7fa8e57db7:/var/www/html# php -m|grep gdgd復(fù)制代碼
curl -L -o redis-4.1.1.tar.gz https://github.com/phpredis/phpredis/archive/4.1.1.tar.gz tar xf redis-4.1.1.tar.gz rm redis-4.1.1.tar.gz mv phpredis-4.1.1 /usr/src/php/ext/redis docker-php-ext-configure redis docker-php-ext-install redis docker-php-ext-enable redis復(fù)制代碼
##查看
root@9d5d4e093dbd:/var/www/html# php -m|grep redisredis
上述內(nèi)容就是PHP環(huán)境中如何使用k8s集群,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。