(1)关闭CentoOS自带的防火墙服务:
systemctl stop iptables firewalld
systemctl disable iptables firewalld
(2)安装etcd,Kubernetes(略)
参考这里
(3)启动所有服务
master:
systemctl start etcd kube-apiserver kube-controller-manager kube-scheduler
node:
systemctl start docker kubelet kube-proxy
(4)创建redis-master Pod和服务
[root@docker1 redis]# cat redis-master-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: redis-master
labels:
name: redis-master
spec:
replicas: 1
selector:
name: redis-master
template:
metadata:
labels:
name: redis-master
spec:
containers:
- name: master
image: kubeguide/redis-master
ports:
- containerPort: 6379
[root@docker1 redis]# cat redis-master-service.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-master
labels:
name: redis-master
spec:
selector:
name: redis-master
ports:
- port: 6379
targetPort: 6379
(5)创建redis-slave Pod和服务
[root@docker1 redis]# cat redis-slave-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: redis-slave
labels:
name: redis-slave
spec:
replicas: 2
selector:
name: redis-slave
template:
metadata:
labels:
name: redis-slave
spec:
containers:
- name: slave
image: kubeguide/guestbook-redis-slave
ports:
- containerPort: 6379
env:
- name: GET_HOSTS_FROM
value: env
[root@docker1 redis]# cat redis-slave-service.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-slave
labels:
name: redis-slave
spec:
selector:
name: redis-slave
ports:
- port: 6379
(6)创建frontend Pod和服务
[root@docker1 redis]# cat frontend-rc.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
[root@docker1 redis]# cat frontend-service.yaml
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
name: frontend
spec:
selector:
name: frontend
type: NodePort
ports:
- port: 80
nodePort: 30001
(7)创建所有Pod和服务
[root@docker1 redis]# kubectl create -f ./
[root@docker1 redis]# kubectl get pods
NAME READY STATUS RESTARTS AGE
frontend-5dznv 1/1 Running 0 31s
frontend-bbgw0 1/1 Running 0 31s
frontend-tkzq1 1/1 Running 0 31s
redis-master-d3jdn 1/1 Running 0 31s
redis-slave-uxnm6 1/1 Running 0 31s
redis-slave-z9ql6 1/1 Running 0 31s
(8)检查服务运行效果
修改网页,显示主机名
[root@docker2 test]# cat index.php
<html ng-app="redis">
<head>
<title>Guestbooktitle>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js">script>
<script src="controllers.js">script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.js">script>
head>
<body ng-controller="RedisCtrl">
<div style="width: 50%; margin-left: 20px">
<h2>Guestbookh2>
echo 'pod name ='.getenv("HOSTNAME");
?>
<form>
<fieldset>
<input ng-model="msg" placeholder="Messages" class="form-control" type="text" name="input"><br>
<button type="button" class="btn btn-primary" ng-click="controller.onRedis()">Submitbutton>
fieldset>
form>
<div>
<div ng-repeat="msg in messages track by $index">
{{msg}}
div>
div>
div>
body>
html>
每个Node上把index.php拷贝到容器[guestbook-php-frontend]
[root@docker2 test]# docker cp index.php d98a29423995:/var/www/html/