Use Kubernetes to create a PHP message board system

Source: Internet
Author: User
Tags redis cluster

Use Kubernetes to create a PHP message board system

This article demonstrates how to use the kubernetes system to create a message board system based on the image files related to kubeguide. Due to limited system resources, the kubernetes cluster has only one master node and slave node.

For Docker local repository and kubernetes cluster configuration, see https://www.bkjia.com/linux/2018-03/151136.htm.

I. Environment Introduction
Operating system version: CentOS linux 7.2 64bit
Master node: 192.168.115.5/24 vm1
Slave Node 1: 192.168.115.6/24 vm2

The access flowchart is as follows:

2. download relevant image files online and integrate them into the local warehouse for 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

3. Prepare the configuration file
1. Create the redis-master rc and service configuration files

# 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 # catredis-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. Create the rc and service configuration files for redis-slave.

# 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 # catredis-slave-service.yaml
ApiVersion: v1
Kind: Service
Metadata:
Name: redis-slave
Labels:
Name: redis-slave
Spec:
Ports:
-Port: 6379
Selector:
Name: redis-slave

3. Create the rc and service configuration files of frontend.

# 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

4. Create 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 main reason for pod creation failure is that the image cannot be pulled from the local warehouse. This error is reported even if the image already exists locally. Because kubernetes's imagePullPolicy obtains the image policy, the default value is Always.

The nginx in our local repository is configured with basic verification, so the following error is reported:
Error syncing pod, skipping: failed to "StartContainer" for "redis-slave" with ErrImagePull: "unauthorized: authentication required"
After disabling nginx basic authentication, try again.

The final solution for using a private repository in Kubernetes and supporting basic authentication is to configure the serviceaccount of kubernetes. Detailed configuration will be introduced in subsequent articles.

Vi. Test
1. view the redis cluster information of the redis master node

# Kubectl exec redis-master-9993n for redis-cli info | grep-A 5 "Replication"
# Kubectl exec redis-slave-gnq41 for redis-cli info | grep-A 5 "Replication"
# Kubectl exec redis-slave-nvscp redis-cli info | grep-A 5 "Replication"

2. web Testing

The firebug plug-in shows that php + apache is providing web services.

VII. Delete 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

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151135.htm

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.