In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how CentOS7.2 deploys simple applications based on Kubernetes". In daily operation, I believe many people have doubts about how CentOS7.2 deploys simple applications based on Kubernetes. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how CentOS7.2 deploys simple applications based on Kubernetes". Next, please follow the editor to study!
Install a simple nginx application with static content with the following figure:
First, we use the replicator to start a nginx Pod with 2 backups. Then hang Service in front, one service can only be accessed inside the cluster, one can be accessed by nodes outside the cluster.
1. Deploy nginx pod and replicator
# cat nginx-rc.yaml apiVersion: v1 kind: ReplicationController metadata: name: nginx-controller spec: replicas: 2 selector: name: nginx template: metadata: labels: name: nginx spec: containers:-name: nginx image: nginx ports:-containerPort: 80
We defined a nginx pod replicator with 2 replicas, and we used nginx docker mirrors.
Create a nginx pod replicator by doing the following:
[root@master test] # kubectl create-f nginx-rc.yaml replicationcontrollers/nginx-controller
Remember to download the gcr.io image first, and then rename it, otherwise it will prompt you to fail. Because the nginx image is also downloaded, the created Pod will have to wait some time before it can be in the running state.
[root@master test] # kubectl get podsNAME READY STATUS RESTARTS AGEnginx 1/1 Running 0 1dnginx-controller-dkl3v 1/1 Running 0 14snginx-controller-hxcq8 1/1 Running 0 14s
We can use the describe command to view information about pod:
[root@master test] # kubectl describe pod nginx-controller-dkl3vName: nginx-controller-dkl3vNamespace: defaultImage (s): nginxNode: 192.168.32.17/192.168.32.17Labels: name=nginxStatus: RunningReason : Message: IP: 172.17.67.2Replication Controllers: nginx-controller (2 replicas created) Containers: nginx: Image: nginx State: Running Started: Wed 30 Dec 2015 02:03:19-0500 Ready: True Restart Count: 0Conditions: Type Status Ready True Events: FirstSeen LastSeen Count From SubobjectPath Reason Message Wed, 30 Dec 2015 02:03:14-0500 Wed 30 Dec 2015 02:03:14-0500 1 {scheduler} scheduled Successfully assigned nginx-controller-dkl3v to 192.168.32.17 Wed, 30 Dec 2015 02:03:15-0500 Wed, 30 Dec 2015 02:03:15-0500 1 {kubelet 192.168.32.17} implicitly required container POD pulled Pod container image "kubernetes/pause" already present on machine Wed 30 Dec 2015 02:03:16-0500 Wed, 30 Dec 2015 02:03:16-0500 1 {kubelet 192.168.32.17} implicitly required container POD created Created with docker id e88dffe46a28 Wed, 30 Dec 2015 02:03:17-0500 Wed, 30 Dec 2015 02:03:17-0500 1 {kubelet 192.168.32.17} implicitly required container POD started Started with docker id e88dffe46a28 Wed 30 Dec 2015 02:03:18-0500 Wed, 30 Dec 2015 02:03:18-0500 1 {kubelet 192.168.32.17} spec.containers {nginx} created Created with docker id 25fcb6b4ce09 Wed, 30 Dec 2015 02:03:19-0500 Wed, 30 Dec 2015 02:03:19-0500 1 {kubelet 192.168.32.17} spec.containers {nginx} started Started with docker id 25fcb6b4ce09
two。 Deploy nginx service accessible within the node
Service's type can be divided into ClusterIP and NodePort, and the default is ClusterIP. This type of Service can only be accessed within the cluster. The configuration file is as follows:
# cat nginx-service-clusterip.yaml apiVersion: v1 kind: Service metadata: name: nginx-service-clusterip spec: ports:-port: 8001 targetPort: 80 protocol: TCP selector: name: nginx
Execute the following command to create the service:
[root@master test] # kubectl create-f. / nginx-service-clusterip.yaml services/nginx-service-clusterip
View the service you created:
[root@master test] # kubectl get serviceNAME LABELS SELECTOR IP (S) PORT (S) kubernetes component=apiserver,provider=kubernetes 10.254.0.1 443/TCPnginx-service-clusterip name=nginx 10.254.234.255 8001/TCP
The above output tells us that the Cluster IP of this Service is 10.254.234.255 and the port is 8001. Let's verify the operation of this PortalNet IP:
Execute the following command on 192.168.32.16:
[root@minion1 ~] # curl-s 10.254.234.255:8001Welcome to nginx! Body {width: 35eme; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} Welcome to nginx!
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.
Thank you for using nginx.
From the previous part of deploying the replicator, we know that nginx Pod is running on 17 nodes. Above we specially access our services from 16 proxy nodes to reflect the reachability of Service Cluster IP on all cluster proxy nodes.
3. Deploy externally accessible nginx service
Let's create a Service of type NodePort, which is accessible outside the cluster. The configuration file is as follows:
Cat nginx-service-nodeport.yaml apiVersion: v1 kind: Service metadata: name: nginx-service-nodeport spec: ports:-port: 8000 targetPort: 80 protocol: TCP type: NodePort selector: name: nginx
Create the service and view it by executing the following command:
[root@master test] # kubectl create-f. / nginx-service-nodeport.yaml You have exposed your service on an external port on all nodes in yourcluster. If you want to expose this service to the external internet You mayneed to set up firewall rules for the service port (s) (tcp:31000) to serve traffic.See http://releases.k8s.io/HEAD/docs/user-guide/services-firewalls.md for more details.services/nginx-service-nodeport [root@master test] # kubectl get serviceNAME LABELS SELECTOR IP (S) PORT (S) kubernetes component=apiserver Provider=kubernetes 10.254.0.1 443/TCPnginx-service-clusterip name=nginx 10.254.234.255 8001/TCPnginx-service-nodeport name=nginx 10.254.210.68 8000/TCP
When you create a service, you need to set the firewall rules, which does not affect the subsequent operations.
View the created service:
[root@master test] # kubectl describe service nginx-service-nodeportName: nginx-service-nodeportNamespace: defaultLabels: Selector: name=nginxType: NodePortIP: 10.254.210.68Port: 8000/TCPNodePort: 31000/TCPEndpoints: 172.17.67.2:80172.17.67.3:80Session Affinity: NoneNo events.
The node-level port of this Service is 31000. Let's verify the operation of this Service:
[root@master test] # curl-s 192.168.32.16:31000Welcome to nginx! Body {width: 35eme; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} Welcome to nginx!
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.
Thank you for using nginx.
[root@master test] # curl-s 192.168.32.17:31000Welcome to nginx! Body {width: 35eme; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} Welcome to nginx!
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.
Thank you for using nginx.
Whether from 16 or 17, you can access our service.
4. Summary
This article is only a simple application, in the application deployment, it is very important to understand the application model of Kubernetes. More in-depth research on Kubernetes is needed.
At this point, the study on "how CentOS7.2 deploys simple applications based on Kubernetes" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.