I wrote before about making a php+nginx environment image and made a php image. This article mainly shares with you some examples of k8s deployment of PHP mirroring, hoping to help you.
So how to use this image?
1. You can directly use docker to run this container
docker run --rm -d --name php -p 80:80 -v /tmp:/app
docker command explanation:
–rm: Prevent docker from generating tags with none Mirror
-d: Make the generated container run in the background
-name: Specify the container name as php to facilitate subsequent operations
-p: Specify the first port 80 is the port number of the host, and the second 80 is the port number of the container
The first port number can be any available port on your host machine, which can be accessed using localhost:port number.
-v: v is the abbreviation of volume, which is to mount the host volume to the container
The first /tmp refers to the path path in the host
The second /app is the path path of the container
Since the nginx root path configured in the basic image webdevops/php-nginx:centos-7-php56 is /app, so it is specified here as /app
Add the file index.php in /tmp
The content is:
<? phpinfo() ?>
After starting the container, you can access the host address + port number. For example, curl localhost:port number will return phpinfo
The path to the configuration file can be seen in the webdevops/php-nginx image document
The nginx configuration file path in effect here is:/opt/docker/etc/nginx/vhost.conf
In this configuration In the file, you can see that the configured root path for monitoring port 80 is /app
You can modify the path
2. Use k8s deployment
Upload the image to the warehouse
docker push image_name
New deployment configuration file: php-deployment.yaml
deployment.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: php spec: replicas: 1 template: metadata: labels: app: php spec: containers: - name: php image: image_address ports: - containerPort: 80 volumeMounts: - mountPath: /app name: php-volume volumes: - name: php-volume hostPath: path: /tmp
New php-service.yaml file
kind: Service apiVersion: v1 metadata: name: php-service namespace: default labels: app: php spec: ports: - name: listener protocol: TCP port: 80 targetPort: 80 selector: app: php type: LoadBalancer externalIPs: - your ip address
Execution command:
kubectl apply -f php-deployment.yaml kubectl apply -f php-service.yaml
You can view it through the following command
kubectl get deployment kubectl get service
You can then get phpinfo by accessing your host IP
Of course, you need to have the index.php file in the /tmp path of the php container node running in your k8s cluster
As for which node is running this container, you can check it through kubecel get pods php
I wrote before making a php+nginx environment image
Created a php image.
So how to use this image?
1. You can directly use docker to run this container
docker run --rm -d --name php -p 80:80 -v /tmp:/app
docker command explanation:
–rm: Prevent docker from generating tags with none Mirror
-d: Make the generated container run in the background
-name: Specify the container name as php to facilitate subsequent operations
-p: Specify the first port 80 is the port number of the host, and the second 80 is the port number of the container
The first port number can be any available port on your host machine, which can be accessed using localhost:port number.
-v: v is the abbreviation of volume, which is to mount the host volume to the container
The first /tmp refers to the path path in the host
The second /app is the path path of the container
Since the nginx root path configured in the basic image webdevops/php-nginx:centos-7-php56 is /app, so it is specified here as /app
Add the file index.php in /tmp
The content is:
<? phpinfo() ?>
After starting the container, you can access the host address + port number. For example, curl localhost:port number will return phpinfo
The path to the configuration file can be seen in the webdevops/php-nginx image document
The nginx configuration file path in effect here is:/opt/docker/etc/nginx/vhost.conf
In this configuration In the file, you can see that the configured root path for monitoring port 80 is /app
You can modify the path
2. Use k8s deployment
Upload the image to the warehouse
docker push image_name
New deployment configuration file: php-deployment.yaml
deployment.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: php spec: replicas: 1 template: metadata: labels: app: php spec: containers: - name: php image: image_address ports: - containerPort: 80 volumeMounts: - mountPath: /app name: php-volume volumes: - name: php-volume hostPath: path: /tmp
New php-service.yaml file
kind: Service apiVersion: v1 metadata: name: php-service namespace: default labels: app: php spec: ports: - name: listener protocol: TCP port: 80 targetPort: 80 selector: app: php type: LoadBalancer externalIPs: - your ip address
Execution command:
kubectl apply -f php-deployment.yaml kubectl apply -f php-service.yaml
You can view it through the following command
kubectl get deployment kubectl get service
You can then get phpinfo by accessing your host IP
Of course, you need to have the index.php file in the /tmp path of the php container node running in your k8s cluster
As for which node is running this container, you can check it through kubecel get pods php.
Related recommendations:
How to use Docker to deploy a PHP development environment
How to deploy a PHP project under Linux?
Deploy multiple versions of php to coexist under Linux
The above is the detailed content of About k8s deployment php mirror instance. For more information, please follow other related articles on the PHP Chinese website!