In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
In the previous article we talked about using Docker to create containers and publish a bulletin board application, and this article will use Kubernetes orchestration tools to manage containers. Kubernetes provides many tool interfaces for scalable, networked, secure, and maintainable containerized applications that go far beyond the capabilities of docker containers themselves.
To verify that our application runs correctly on Kubernetes, we will deploy our application on a development machine using Docker Desktop's built-in Kubernetes environment and deliver it to run on a full Kubernetes cluster in production. Kubernetes features in Docker Desktop are consistent with production Kubernetes clusters, so even on a development environment, your application has all the features of production Kubernetes clusters.
Using YAML to create apps
Create a file named bb.yaml, as shown in Figure 1.1.
apiVersion: apps/v1
kind: Deployment
metadata:
name: bb-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
bb: web
template:
metadata:
labels:
bb: web
spec:
containers:
- name: bb-site
image: bulletinboard:1.0
---
apiVersion: v1
kind: Service
metadata:
name: bb-entrypoint
namespace: default
spec:
type: NodePort
selector:
bb: web
ports:
- port: 8080
targetPort: 8080
nodePort: 30001
Figure 1.1
The YAML file of Kubernetes above has 2 object structures and uses "---" as the delimiter. If there is only one object in the YAML file, the delimiter can be omitted.
Deployment object description Create a pod group with 1 copy of the container, and then create it based on mirror bulletin board:1.0.
The Service object describes creating a NodePort-type service that routes traffic from port 30001 on the host to port 8080 on the pods content container, allowing you to access the bulletin board application from IP:30001 on the host.
Kubernetes YAML may seem long and complex at first, but it almost always follows the same pattern.
(1)apiVersion is used to specify the version of the Kubernetes API
(2), kind are used to specify resource types, which can be Deployment, Service, Namespace, ConfigMap, ServiceAccount, etc.
(3)metadata, specify the metadata information of the Pod, including name, namespace, labels, etc.
(4), spec, specifying the configuration required for container, storage, volume, and other kubernetes objects.
Publish and test your app
1. In the directory where bb.yaml is located, execute the following command.
# kubectl apply -f bb.yaml
When you see the following output, the app is published successfully.
deployment.apps/bb-demo created
service/bb-entrypoint created
2. Execute the following commands to ensure normal deployment.
# kubectl get deployments
If the output message is as follows, it indicates normal operation.
NAME READY UP-TO-DATE AVAILABLE AGE
bb-demo 1/1 1 1 80m
3. Execute the following command to view service information
# kubectl get services
The output information is as follows
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
bb-entrypoint NodePort 10.99.53.144 8080:30001/TCP 20s
kubernetes ClusterIP 10.96.0.1 443/TCP 24h
You can see our published service bb-entrypoint. The external access port is 30001. The default port range of NodePort is: 30000-32767. You can know it by outputting the kube-apiserver command (this command is in the apiserver container).
--service-node-port-range portRange
A port range to reserve for services with NodePort visibility. Example: '30000-32767'. Inclusive at both ends of the range. (default 30000-32767)
4. Access your application through http://localhost:30001. You will see the following interface, as shown in Figure 1.2, indicating that the application deployment is successful. The next step is to test, build, publish, and share.
Figure 1.2
5, delete the application, you can make the following command
# kubectl delete -f bb.yaml
or
# kubectl delete deploy bb-demo# kubectl delete service bb-entrypoint
See Figure 1.3 below.
Figure 1.3
At this point, we have successfully deployed our application to the Kubernetes environment of the development machine using Docker Desktop. We haven't done much work on Kubernetes yet, but now that the door is open, you can start adding other components to your app and use all of Kubernetes 'features. In addition, we should also strengthen the understanding of YAML file learning.
Note: YAML files can generate templates based on existing deployment, pod, and service that are running, and then modify them based on this template.
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: 300
*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
Net time\ ad.service-IP / set / ynet stop w32timenet start w32time
© 2024 shulou.com SLNews company. All rights reserved.