A simple kubernetes Application deployment example

Source: Internet
Author: User
Tags kubernetes deployment

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.