使用Kubernetes创建PHP留言板系统

本文将演示使用kubernetes系统基于 kubeguide相关的镜像文件创建基于php和Redis的留言板系统,因为系统资源有限,kubernetes集群只有一个master节点和slave节点。

Docker本地仓库与kubernetes集群配置请查看 https://www.linuxidc.com/Linux/2018-03/151136.htm

一、环境介绍
操作系统版本:CentOS linux 7.2 64bit
Master节点:192.168.115.5/24 vm1
Slave节点1:192.168.115.6/24 vm2

使用Kubernetes创建PHP留言板系统

访问流程图如下:

使用Kubernetes创建PHP留言板系统

二、在线下载相关的镜像文件,并纳入本地仓库统一管理

# docker pull kubeguide/redis-master
# docker pull kubeguide/guestbook-php-frontend
# docker pull kubeguide/guestbook-redis-slave
# docker tag kubeguide/redis-master registry.fjhb.cn/redis-master
# docker tag kubeguide/guestbook-php-frontend registry.fjhb.cn/guestbook-php-frontend
# docker tag kubeguide/guestbook-redis-slave registry.fjhb.cn/guestbook-redis-slave
# docker push registry.fjhb.cn/redis-master
# docker push registry.fjhb.cn/guestbook-php-frontend
# docker push registry.fjhb.cn/guestbook-redis-slave
# curl -u yang:123 -XGET https://registry.fjhb.cn/v2/_catalog
# docker images |grep fjhb

使用Kubernetes创建PHP留言板系统

三、配置文件准备
1、创建redis-master rc和service配置文件

# cat 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: registry.fjhb.cn/redis-master
        ports:
        - containerPort: 6379# cat 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

2、创建redis-slave的rc和service配置文件

# cat 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: registry.fjhb.cn/guestbook-redis-slave
        env:
        - name: GET_HOSTS_FROM
          value: env
        ports:
        - containerPort: 6379# cat redis-slave-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: redis-slave
  labels:
    name: redis-slave
spec:
  ports:
  - port: 6379
  selector:
name: redis-slave

3、创建frontend的rc和service配置文件

# cat 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: registry.fjhb.cn/guestbook-php-frontend
        env:
        - name: GET_HOSTS_FROM
          value: env
        ports:
        - containerPort: 80# cat frontend-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: frontend
  labels:
    name: frontend
spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 30001
  selector:
name: frontend

四、在master节点上创建rc 和 sevices

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/49f86a67246257c1f3ca38e2cd84dacd.html