实例结构
创建redis-master-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: redis-master
spec:
replicas: 1
selector:
name: redis-master
template:
metadata:
name: redis-master
labels:
name: redis-master
spec:
containers:
- name: redis-master
image: kubeguide/redis-master
ports:
- containerPort: 6379
发布到kubernetes集群,自动创建pod
kubectl create -f redis-master-controller.yaml
kubectl get rc
kubectl get pods
创建redis-master-service.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-master
labels:
name: redis-master
spec:
ports:
- port: 6379
targetPort: 6379
selector:
name: redis-master
创建service
kubectl create -f redis-master-service.yaml
kubectl get services
创建redis-slave-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: redis-slave
spec:
replicas: 2
selector:
name: redis-slave
template:
metadata:
name: redis-slave
labels:
name: redis-slave
spec:
containers:
- name: redis-slave
image: kubeguide/guestbook-redis-slave
env:
- name: GET_HOSTS_FROM
value: env
ports:
- containerPort: 6379
创建
kubectl create -f redis-slave-controller.yaml
kubectl get rc
kubectl get pods
创建redis-slave-service.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-slave
labels:
name: redis-slave
spec:
ports:
- port: 6379
selector:
name: redis-slave
创建
kubectl create -f redis-slave-service.yaml
kubectl get services
创建frontend-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: frontend
labels:
name: frontend
spec:
replicas: 3
selector:
name: frontend
template:
metadata:
labels:
name: frontend
spec:
containers:
- name: frontend
image: kubeguide/guestbook-php-frontend
env:
- name: GET_HOSTS_FROM
value: env
ports:
- containerPort: 80
创建
kubectl create -f frontend-controller.yaml
kubectl get rc
kubectl get pods
创建frontend-service.yaml
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
name: frontend
spec:
type: NodePort
ports:
- port: 80
nodePort: 30001
selector:
name: frontend
创建
kubectl create -f frontend-service.yaml
kubectl get services
全部启动后的kubernetes-ui
删除
kubectl delete -f frontend-controller.yaml
replicationcontroller "frontend" deleted
kubectl delete -f redis-master-controller.yaml
replicationcontroller "redis-master" deleted
kubectl delete -f redis-slave-controller.yaml
replicationcontroller "redis-slave" deleted
kubectl delete -f redis-slave-service.yaml
service "redis-slave" deleted
kubectl delete -f redis-master-service.yaml
service "redis-master" deleted
kubectl delete -f frontend-service.yaml
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。