In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to realize the message board function of Kubernetes". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Basic environment
System version: CentOS Linux release 7.5.1804 (Core)
Kubernetes version: kubernetes1.3
Project background
The Guestbook message board system will be built by Pod, RC, Service and other resource objects, and a "Hello World" message will be displayed on the web page after successful launch. Its system architecture is a distributed Web application based on PHP+Redis. The front-end PHP Web website completes the query and add function of user messages by visiting the back-end Redis. At the same time, Redis is deployed in Master+Slave mode to achieve the ability to separate data from reading and writing.
Project architecture
The Web layer is an Apache service based on PHP pages, which starts three instances to form a cluster to realize the load balance of visiting the website. Redis Master starts one instance for write operation (add message), and Redis Slave starts two instances for read operation (read message). The data synchronization between Redis Master and Slave is accomplished by the data synchronization mechanism provided by Redis.
Service deployment 1. Redis Master deployment 1.1 create redis-master RC
You can define a Service, and then a RC to create and control the associated Pod, or define a RC to create a Pod, and then define the Service associated with it.
First create a RC definition file named redis-master redis-master-controller.yaml for redis-master.
# cat redis-master-controller.yaml apiVersion: v1kind: ReplicationController # indicates that this is a RCmetadata: name: redis-master labels: name: redis-masterspec: replicas: 1 selector: name: redis-master template: metadata: labels: name: redis-masterspec: containers:-name: master image: kubeguide/redis-master ports:-containerPort: 6379
After the creation is completed, publish to the cluster on the master node
# kubectl create-f redis-master-controller.yaml replicationcontroller/redis-master created
Confirm the successful creation of RC and Pod with the kubectl get command
# kubectl get rcNAME DESIRED CURRENT READY AGEredis-master 110 70s# kubectl get pods-o wide | grep redisredis-master-j58mw 1 Running 1 Running 0 3m59s 172.17.39.7 192.168.200.1301.2 create redis-master service
After redis-master Pod has been created and is running properly, after creating the Service associated with it
# cat redis-master-service.yaml apiVersion: v1kind: Servicemetadata: name: redis-master labels: name: redis-masterspec: ports:-port: 6379 targetPort: 6379 selector: name: redis-master
Run the kubectl create command to create the service
# kubectl create-f redis-master-service.yaml service/redis-master created# kubectl get services | grep redis-masterredis-master ClusterIP 10.0.0.116 6379/TCP 40s2. Redis slave deployment
This example starts two replicas that start the redis-slave service, and the Redis process on each copy synchronizes data with redis-master, forming a Redis cluster with read-write separation with redis-master. The PHP web page of the message board reads the message data by visiting the redis-slave service.
2.1 create redis-slave RC# cat redis-slave-controller.yaml apiVersion: v1kind: ReplicationControllermetadata: name: redis-slave labels: name: redis-slavespec: replicas: 2 selector: name: redis-slave template: metadata: labels: name: redis-slavespec: containers:-name: slave image: kubeguide/guestbook-redis-slave env:-name: GET_HOSTS_FROM value: env Ports:-containerPort: 6379
An environment variable GET_HOSTS_FROM=env is set in the configuration section of the container, which means to get the IP address information of the redis-master service from the environment variable.
The startup script / run.sh in the redis-slave image is as follows:
# kubectl create-f redis-slave-controller.yaml replicationcontroller/redis-slave created# kubectl get rc | grep redisredis-master 1 1 1 45mredis-slave 2 22 103s# kubectl get pod | grep redisredis-master-j58mw 1 Running 0 45mredis-slave-c42bx 1 45mredis-slave-c42bx 1 Running 0 2m3sredi- Slave-s74b8 1 Running 1 Running 0 2m3s2.2 create redis-slave service
Create redis-slave-related Service services, similar to redis-master services.
# cat redis-slave-service.yamlapiVersion: v1kind: Servicemetadata: name: redis-slave labels: name: redis-slavespec: ports:-port: 6379 targetPort: 6379 selector: name: redis-slave
Run kubectl to create Service
# kubectl create-f redis-slave-service.yaml service/redis-slave created# kubectl get svc | grep redisredis-master ClusterIP 10.0.0.116 6379/TCP 39mredis-slave ClusterIP 10.0.0.173 6379/TCP 49s
3. Deploy frontend3.1 create deployment frontend rc
# 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: kubeguide/guestbook-php-frontend
Env:
-name: GET_HOSTS_FROM
Value: env
Ports:
-containerPort: 80
An environment variable GET_HOSTS_FROM=env is set in the configuration section of the container, which means to get the IP address information of redis-master and redis-slave services from the environment variable.
# kubectl create-f frontend-controller.yaml replicationcontroller/frontend created
View the created
# kubectl get rcNAME DESIRED CURRENT READY AGEfrontend 3 3 3 5m1sredis-master 1 1 1 67mredis-slave 2 2 2 24m# kubectl get podsNAME READY STATUS RESTARTS AGEfrontend-mnd85 1/1 Running 0 5m43sfrontend-pmpdb 1 Running 0 5m43sfrontend-zd2n5 1 5m43s3.2 1 Running 0 5m43s3.2 create deployment frontend service finally create frontend Service The main purpose is to use the NodePort of Service to map a port accessible by the external network to the Service in the Kuberbetes cluster, so that the external network can access the services in the cluster through NodeIP+NodePort.
# cat frontend-service.yaml
ApiVersion: v1
Kind: Service
Metadata:
Name: frontend
Labels:
Name: frontend
Spec:
Type: NodePort
Ports:
-port: 80
NodePort: 30003
Selector:
Name: frontend
Run the kubectl create command to publish to the cluster
# kubectl create-f frontend-service.yamlservice/frontend created# kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEfrontend NodePort 10.0.0.145 80:30003/TCP 24s
Web page browsing
Http://192.168.200.129:30003/, http://192.168.200.130:30003/ remarks: IP of Node node
If you log in again, you will see a message, indicating that there is no problem with data reading and writing.
This is the end of the content of "how to achieve the message board function of Kubernetes". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.