Create a PHP message board system with Kubernetes

Source: Internet
Author: User
Tags redis cluster

This article demonstrates the use of the kubernetes system to create a PHP and Redis-based message board system based on Kubeguide-related image files, because system resources are limited, and the Kubernetes cluster has only one master node and slave node.
Docker local warehouse and kubernetes cluster configuration Please review the previous article.

I. Introduction to the Environment
OS version: CentOS Linux 7.2 64bit
Master node: 192.168.115.5/24 vm1
Slave node 1:192.168.115.6/24 vm2

Visit the flowchart below:

Second, online download the relevant image files, and into the local warehouse unified management

# 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


Three, configuration file preparation
1. Create the Redis-master RC and service configuration files

# cat redis-master-controller.yaml apiVersion: v1kind: ReplicationControllermetadata:  name: redis-masterspec:  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: v1kind: Servicemetadata:  name: redis-master  labels:    name: redis-masterspec:  ports:  - port: 6379    targetPort: 6379  selector:name: redis-master

2. Create RC and service profiles for Redis-slave

# cat redis-slave-controller.yamlapiVersion: v1kind: ReplicationControllermetadata:  name: redis-slavespec:  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: v1kind: Servicemetadata:  name: redis-slave  labels:    name: redis-slavespec:  ports:  - port: 6379  selector:name: redis-slave

3. Create RC and service profiles for Frontend

# cat frontend-controller.yamlapiVersion: v1kind: ReplicationControllermetadata:  name: frontend  labels:    name: frontendspec:  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.yamlapiVersion: v1kind: Servicemetadata:  name: frontend  labels:    name: frontendspec:  type: NodePort  ports:  - port: 80    nodePort: 30001  selector:name: frontend

Iv. creating RC and Sevices on the master node

# kubectl create -f redis-master-controller.yaml # kubectl create -f redis-slave-controller.yaml # kubectl create -f frontend-controller.yaml # kubectl create -f redis-master-service.yaml # kubectl create -f redis-slave-service.yaml # kubectl create -f frontend-service.yaml # kubectl get rc# kubectl get svc# kubectl get pod

# kubectl describe pod redis-slave-gsk1p

The reason why the pod could not be created is that the image cannot be pulled from the local repository, even if the image is already present locally. Because Kubernetes's imagepullpolicy gets the mirror policy default value is always

The nginx of our local warehouse is configured with basic verification, so the error is as follows
Error syncing pod, skipping:failed to ' startcontainer ' for ' Redis-slave ' with errimagepull: ' Unauthorized:authentication Required
After you turn off Nginx Basic authentication, try again, and it sure is no problem.

The final solution for using a private warehouse in Kubernetes and supporting Basic authentication is to configure the Kubernetes ServiceAccount, which will be described in a later article for detailed configuration.

VI. Testing
1. View Redis cluster information for Redis master node

2. Web Testing

Through the Firebug plug-in you can see that Php+apache is providing Web services

Vii. removal of RC and service

# kubectl delete -f frontend-controller.yaml# kubectl delete -f redis-master-controller.yaml# kubectl delete -f redis-slave-controller.yaml# kubectl delete -f redis-slave-service.yaml# kubectl delete -f redis-master-service.yaml# kubectl delete -f frontend-service.yaml

Create a PHP message board system with Kubernetes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.