安装部署一个tomcat+mysql应用
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec: //spec中是对RC对象的具体描述
replicas: 5
selector:
app: myweb
template:
metadata:
labels: //选择器,用来选择对象的
app: myweb //我选择了标签为app: myweb的pod
spec: //对pod模版的具体描述
containers:
- image: kubeguide/tomcat-app:v1
name: myweb
resources:
limits:
cpu: "2"
memory: 4Gi
ports: 22
- containerPort: 8080
env:
- name: MYSQL_SERVICE_HOST
value: 'mysql'
- name: MYSQL_SERVICE_PORT
value: '3306'
创建tomcat service
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
selector:
app: myweb
type: NodePort
ports:
- port: 8888
nodePort: 30008
targetPort: 8080
mysql rc
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas: 1
selector:
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 service
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
selector:
app: mysql
type: NodePort
ports:
- port: 3306
nodePort: 30006
targetPort: 3306
参考:
https://github.com/rook/rook/tree/master/cluster/examples/kubernetes
mysql.yaml wordpress.yaml