发布MySQL RC
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: mysql
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
发布命令 kubectl create -f mysql-rc.yaml
查看创建的RC kubectl get rc
查看Pod的创建情况 kubectl get pods
发布MySQL Service
mysql-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
创建Service kubectl create -f mysql-svc.yaml
查看刚刚创建的Service kubectl get svc
发布Tomcat RC
myweb-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec:
replicas: 2
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: kubeguide/tomcat-app:v1
ports:
- containerPort: 8080
env:
- name: MYSQL_SERVICE_HOST
value: 10.111.122.226
创建RC kubectl create -f myweb-rc.yaml
发布Tomcat Service
myweb-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30001
selector:
app: myweb
创建Service kubectl create -f myweb-svc.yaml
访问测试
http://192.168.18.11:30001/
|