About k8s deployment php mirror instance

小云云
Release: 2023-03-21 06:16:02
Original
4246 people have browsed it

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
Copy after login
Copy after login

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() ?>
Copy after login
Copy after login

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
Copy after login
Copy after login

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
Copy after login
Copy after login

Execution command:

kubectl apply -f php-deployment.yaml
kubectl apply -f php-service.yaml
Copy after login
Copy after login

You can view it through the following command

kubectl get deployment
kubectl get service
Copy after login
Copy after login

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
Copy after login
Copy after login

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() ?>
Copy after login
Copy after login

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
Copy after login
Copy after login

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
Copy after login
Copy after login

Execution command:

kubectl apply -f php-deployment.yaml
kubectl apply -f php-service.yaml
Copy after login
Copy after login

You can view it through the following command

kubectl get deployment
kubectl get service
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!