k8s tomcat+mysql 入门实例

文件:mysql-rc.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql-rc
spec:
  replicas: 1
  selector:
    app: mysql-pod
  template:
    metadata:
      labels:
        app: mysql-pod
    spec:
      containers:
      - name: mysql-container
        image: mysql:5.7
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"

 

准备文件:

文件:myweb-rc.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: myweb-rc
spec:
  replicas: 1
  selector:
    app: myweb-pod
  template:
    metadata:
      labels:
        app: myweb-pod
    spec:
      containers:
        - name: myweb-container
          image: kubeguide/tomcat-app:v1
          ports:
          - containerPort: 8080
          env:
          - name: MYSQL_SERVICE_HOST
            value: 'mysql-svc'
          - name: MYSQL_SERVICE_PORT
            value: '3306'

运行命令

kubectl create -f mysql-rc.yaml

kubectl create -f myweb-rc.yaml

 

检查命令

kubectl get pos

出现类似下面情况:

mysql-rc-cbsdn                        1/1     Running   1          2d4h
myweb-rc-7wkqk                        1/1     Running   0          37m

确保两个Pod都是运行状态

 

本机访问 http://192.168.10.4:30002/demo 出现如下画面:

192.168.10.4是myweb-rc-7wkqk NodeIP的地址

k8s tomcat+mysql 入门实例_第1张图片

你可能感兴趣的:(容器)