文件: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的地址

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐