Description
We use an example to demonstrate the basic configuration of the Kubernetes deployment application.
This is a relatively simple example of a tomcat application plus a MySQL database
Running a simple webappp in Tomcat, this app accesses MySQL to get the data. and displayed on the page. For demonstration and simplification purposes, as long as the program is properly connected to the database, it automatically completes the preparation of the corresponding table creation and initialization data. So when we access the app through a browser, we'll show a table page with the data coming from the database.
Configuration
We create a webapp directory under the/root/k8s-yaml/directory and create four files in this directory:
.├── mysql-dm.yaml├── mysql-svc.yaml├── myweb-dm.yaml└── myweb-svc.yaml
The contents of these four documents are as follows:
Mysql-dm.yaml:
apiVersion: apps/v1beta1kind: Deploymentmetadata: name: mysqlspec: replicas: 1 selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:5.7 ports: - containerPort: 3306 env: - name: MYSQL_ROOT_PASSWORD value: "123456"
Mysql-svc.yaml:
apiVersion: v1kind: Servicemetadata: name: mysqlspec: ports: - port: 3306 selector: app: mysql``
Myweb-dm.yaml:
apiVersion: apps/v1beta1kind: Deploymentmetadata: name: mywebspec: replicas: 2 selector: matchLabels: app: myweb template: metadata: labels: app: myweb spec: containers: - name: myweb image: kubeguide/tomcat-app:v1 ports: - containerPort: 8080 env: - name: MYSQL_SERVICE_HOST value: ‘mysql‘ - name: MYSQL_SERVICE_PORT value: ‘3306
Myweb-svc.yaml:
apiVersion: v1kind: Servicemetadata: name: mywebspec: type: NodePort ports: - port: 8080 nodePort: 30001 selector: app: myweb
We start with the following methods:
kubectl apply -f ./
Access:
/HTTP $node _ip:30001/demo
A simple kubernetes Application deployment example