美文网首页
Kubernetes 入门:部署 MySQL 服务和 Tomca

Kubernetes 入门:部署 MySQL 服务和 Tomca

作者: awker | 来源:发表于2019-03-25 19:01 被阅读0次

1、部署 MySQL

# cat mysql-rc.yaml 
kind: ReplicationController
apiVersion: v1
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.6
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"

# kubectl create -f mysql-rc.yaml   
# cat mysql-svc.yaml 
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
    - port: 3306
  selector:
    app: mysql

# kubectl create -f mysql-svc.yaml

2、部署 Tomcat
使用 nodeName: cnszkf01011 把 Pod 部署到指定的 Node 节点

# cat myweb-rc.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  name: myweb
spec:
  replicas: 1
  selector:
    app: myweb
  template:
    metadata:
      labels:
        app: myweb
    spec:
      nodeName: cnszkf01011
      containers:
        - name: myweb
          image: kubeguide/tomcat-app:v1
          ports:
          - containerPort: 8080
          env:
          - name: MYSQL_SERVICE_HOST
            value: 'mysql'

# kubectl create -f myweb-rc.yaml
# cat myweb-svc.yaml 
apiVersion: v1
kind: Service
metadata:
  name: myweb
spec:
  type: NodePort
  ports:
    - port: 8080
      nodePort: 8400
  selector:
    app: myweb

# kubectl create -f myweb-svc.yaml

3、查看结果

# kubectl get nodes -o wide
NAME          STATUS   ROLES    AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION              CONTAINER-RUNTIME
cnszkf01011   Ready    <none>   18d   v1.12.3   10.3.200.105   <none>        CentOS Linux 7 (Core)   3.10.0-693.2.2.el7.x86_64   docker://18.9.0
cnszkf01012   Ready    <none>   18d   v1.12.3   10.3.200.106   <none>        CentOS Linux 7 (Core)   3.10.0-693.2.2.el7.x86_64   docker://18.9.0

# kubectl get pods -o wide
NAME          READY   STATUS    RESTARTS   AGE   IP            NODE          NOMINATED NODE
mysql-65c4g   1/1     Running   0          20m   172.30.56.2   cnszkf01012   <none>
myweb-l6r6w   1/1     Running   0          13m   172.30.96.7   cnszkf01011   <none>

# kubectl get rc -o wide
NAME    DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES                    SELECTOR
mysql   1         1         1       20m   mysql        mysql:5.6                 app=mysql
myweb   1         1         1       13m   myweb        kubeguide/tomcat-app:v1   app=myweb

# kubectl get service -o wide
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE   SELECTOR
kubernetes   ClusterIP   10.254.0.1       <none>        443/TCP         19d   <none>
mysql        ClusterIP   10.254.199.193   <none>        3306/TCP        20m   app=mysql
myweb        NodePort    10.254.119.230   <none>        8080:8400/TCP   13m   app=myweb

参考:
1、Kubernetes 集群部署:和我一步步部署 kubernetes 集群
2、部署 MySQL 服务和 Tomcat 服务:《Kubernetes权威指南 从Docker到Kubernetes实践全接触》1.3 节

相关文章

网友评论

      本文标题:Kubernetes 入门:部署 MySQL 服务和 Tomca

      本文链接:https://www.haomeiwen.com/subject/hxnbvqtx.html