1. Create a mariadb image and initialize the database in the Dockerfile, source code:
https://github.com/zhanggq/mariadb
2. Make your own web mirror, write the back-end in go, use amaze in the front-end, open port 8082, the source code is not available for the time being
3. Click Create on Dashboard, paste yaml, and start mariadb rc
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas: 1
selector:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/zhanggq/mariadb:v10.1
name: mysql
resources:
limits:
cpu: "2"
memory: 2Gi
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
4. Start mariadb svc
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- name: mysql-svc
port: 3306
targetPort: 3306
nodePort: 31101
selector:
app: mysql
type: NodePort
5. Start amaze rc
apiVersion: v1
kind: ReplicationController
metadata:
name: amaze
spec:
replicas: 1
selector:
app: amaze
template:
metadata:
labels:
app: amaze
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/zhanggq/amaze:v1.0
name: amaze
resources:
limits:
cpu: "1"
memory: 1Gi
ports:
- containerPort: 8082
6. start amaze svc
apiVersion: v1
kind: Service
metadata:
name: amaze
spec:
ports:
- name: amaze-svc
port: 8082
targetPort: 8082
nodePort: 30082
selector:
app: amaze
type: NodePort
problems encountered
1. Docker starts the container and reports an error:
docker: Error response from daemon: mkdir /var/lib/docker/overlay/64d4cbac6ef69d5b84fc753e83dc2849f14e43177d0e9d
a532eb61499ce7e2fc-init/merged/dev/shm: invalid argument.
Workaround: Upgrade the kernel
Original kernel Kernel Version: 3.10.0-229.el7.x86_64
After upgrade kernel 4.6.0-1.el7.elrepo.x86_64
2. Manually changed the configuration in the web application and remotely connected to the mysql database 10.233.104.69:3306
Later, I found that I didn't understand the concept of Service in Kubernetes. The specific analysis is described below.