Orange Pi 4 and Raspberry Pi 4B build K8S cluster practice six: App service deployment
Directory
1. Description
1.1 Regarding the WebApp of the PHP + Nginx system, two deployment modes will be practiced here:
1.2 Configuration list
2. WebApp deployment of PHP + Nginx system
2.1 Single-node multi-container mode A
2.1.1 Preparations
2.2.2 Deployment
2.2.3 Access Effect
2.2 Multi-node single container mode B
2.2.1 Preparations
2.2 Configure virtual host
3. Java Springboot App deployment
3.1 Create a springboot-hello project in VS Code
3.2 Create an App image
3.3 deployment
4. Session session keeps setting
5. Problems encountered
6. Reference
1. Description
– According to the previous k8s foundation, I plan to set up two different virtual hosts to run on this K8s cluster, one is the WebApp of the PHP + Nginx system, and the other is the WebApp of the Java SpringBoot system.
1.1 Regarding the WebApp of the PHP + Nginx system, two deployment modes will be implemented here:
Single-node multi-container mode A – is a cross-container design mode, the purpose is to run multiple containers (processes) with super-intimate relationships on a single host, so the container management system needs to treat it as an atom The unit conducts unified scheduling. The Pod concept designed by the Kubernetes orchestration system is one of the implementations of this design pattern.
Multi-node single-container collaboration mode B – Distribute each instance of a distributed application (eg: nginx, php, mariadb…) to multiple nodes and run in single-node mode
1.2 Configuration List
– wwwroot is the file directory where pvc was defined before, in the form of: /data0/nfs/iot-age-wwwroot-pvc-202ba85a-fd3f-4817-98ea-6764f9ec0d55
pattern
host domain name
system
point to hosts ip
Project storage path
A
phpmyadmin.k8s-t2 .com
PHP
192.168.0.106
/var/ www/app
B
t1.k8s-t1.com
PHP
192.168.0.106
wwwroot/t1
B
t2.k8s -t1.com
PHP
192.168.0.106
wwwroot /t2
A
springboothello.k8s-t2.com
Java
192.168.0.106
/app.jar
< /table>
2. WebApp deployment of PHP + Nginx system
2.1 Single-node multi-container mode A
2.1.1 Preparations
Using the well-known phpmyadmin as a demonstration app, first package it into a mirror with the buildkit tool, and upload it to hub.docker.com (this is my mirror linkhttps://hub.docker.com/repository/ docker/bennybi/phpmyadmin/general) .
# This Dockerfile uses the latest version of the Bitnami PHP-FPM Docker image
FROM alpine:latest
# Copy app's source code to the /app directory
COPY ./app
# The application's directory will be the working directory
WORKDIR /app
2.2.2 Deployment
According to the idea of mode A, mode A is used to quickly and conveniently deploy a single application, so I unified the relevant settings into the definition in the phpmyadmin.k8s-t2.com.yaml file, where the rules:
The project name or domain needs to replace “.” with “-” to switch to the deployment name, such as phpmyadmin.k8s-t2.com => phpmyadmin-k8s-t2-com
In the container, use the image just uploaded as initContainer to deploy the code
nginx, php-fpm serves the container, nginx calls local-php-fpm:9000 to explain the php runtime logic
When packaging, you need to pre-define the connection to the database service in the code, such as: my-release-mariadb-galera.default, no additional configmap is made here
This is the error encountered when using phpmyadmin:
Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.
I quickly realized that this was caused by the out-of-sync sessions caused by access requests being assigned to different php pods for processing. Solution: set ingress, nginx service, and php service sessions to keep (that is, the same client ip access to the same pod, with an expiration time)
The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Java skill treeHomepageOverview 118798 people are studying systematically