參考 《kubernetes 權威指南》一節的 從一個簡單例子開始,操做實錄。node
一、Java Web 應用結構mysql
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas: 1
selector:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"web
# kubectl create -f mysql-rc.yaml
#
kubectl get rc
#kubectl get pods
#kubectl get pods
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
# kubectl create -f mysql-svc.yamlsql
# kubectl get svcapi
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec:
replicas: 1
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: kubeguide/tomcat-app:v1
ports:
- containerPort: 8080瀏覽器
# kubectl create -f myweb-rc.yamltomcat
# kubectl get podapp
kind: Service
metadata:
name: myweb
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30002
selector:
app: mywebide
# kubectl create -f myweb-svc.yamlui
# kubectl get svc
防火牆須要提早關閉:
systemctl stop firewalld