2019独角兽企业重金招聘Python工程师标准>>>
1. 制作mariadb镜像,在Dockerfile中初始化数据库,源码:
https://github.com/zhanggq/mariadb
2. 制作自己的web镜像,后端用go编写,前端用的amaze,开放端口8082,源码暂不提供
3. Dashboard上点创建,粘贴yaml,启动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. 启动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. 启动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. 启动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
遇到的问题
1. docker启动容器报错:
docker: Error response from daemon: mkdir /var/lib/docker/overlay/64d4cbac6ef69d5b84fc753e83dc2849f14e43177d0e9d
a532eb61499ce7e2fc-init/merged/dev/shm: invalid argument.
解决办法:升级内核
原内核Kernel Version: 3.10.0-229.el7.x86_64
升级后内核4.6.0-1.el7.elrepo.x86_64
2. 手工改了一下web应用里面的配置,远程连接mysql数据库10.233.104.69:3306
后来发现其实是没搞清楚Kubernetes中Service的概念。具体的分析在下文介绍。