数据库
首页 > 数据库> > kubernetes案例 tomcat+mysql

kubernetes案例 tomcat+mysql

作者:互联网

该文章参考《kubernetes 权威指南》

环境:

[root@master tomcat-mysql]# kubectl get nodes
NAME      STATUS    AGE
node1     Ready     9d
node2     Ready     9d

需要启动两个容器myweb和mysql。

myweb配置文件:

ReplicationController配置文件

[root@master tomcat-mysql]# vim myweb-rc.yaml
kind: ReplicationController
metadata:
  name: myweb
spec:
  replicas: 1
  selector:
    app: myweb
  template:
    metadata:
      labels:
        app: myweb
    spec:
      containers:
        - name: myweb
          image: docker.io/kubeguide/tomcat-app:v1
          ports:
          - containerPort: 8080
          env:
          - name: MYSQL_SERVICE_PORT
            value: '3306'

Service配置文件

[root@master tomcat-mysql]# vim myweb-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: myweb
spec:
  type: NodePort
  ports:
    - port: 8080
      nodePort: 30001
  selector:
    app: myweb

启动:

[root@master tomcat-mysql]# kubectl create -f myweb-rc.yaml
[root@master tomcat-mysql]# kubectl create -f myweb-svc.yaml
[root@master tomcat-mysql]# kubectl get rc
NAME      DESIRED   CURRENT   READY     AGE
myweb     1         1         1         5h
[root@master tomcat-mysql]# kubectl get svc
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes   10.254.0.1      <none>        443/TCP          9d
myweb        10.254.255.33   <nodes>       8080:30001/TCP   5h
mysql配置文件:


[root@master tomcat-mysql]# vim mysql-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: docker.io/mysql:5.6
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"

 



 

标签:myweb,tomcat,kubernetes,master,mysql,root,name
来源: https://www.cnblogs.com/winter1519/p/11213789.html