In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about how to deploy springboot in kubernates, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
1. Create a Springboot application
List-1.1
Import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @ RestController public class HelloController {@ RequestMapping (value = "/") public String hello () {System.out.println ("hello method"); return "Hello, k8s!";}}
Then mvn clean package, package, get app.jar, and put it in the same directory as Dockerfile.
List-1.2
Mjduan@mjduan-ubuntu:/opt/software/docker/springboot-k8s$ ll total 676796 drwxr-xr-x 2 mjduan mjduan 4096 February 15 15:43. / drwxr-xr-x 4 mjduan mjduan 4096 February 15 15:30.. /-rw-r--r-- 1 mjduan mjduan 16674428 February 15 15:31 app.jar-rw-r--r-- 1 mjduan mjduan 362 February 15 15:37 Dockerfile2, make an image
The content of Dockerfile is
List-2.1
FROM openjdk:8 ADD app.jar / opt/app/app.jar RUN bash-c 'touch / opt/app/app.jar' # Open port 8080 EXPOSE 8080 ENV TZ=Asia/Shanghai RUN ln-snf / usr/share/zoneinfo/$TZ / etc/localtime & & echo $TZ > / etc/timezone # configure commands ENTRYPOINT executed after container startup ["java", "- Djava.security.egd=file:/dev/./urandom", "- jar" "/ opt/app/app.jar"]
Then execute the command to get the mirror image
List-2.2
Mjduan@mjduan-ubuntu:/opt/software/docker/springboot-k8s$ docker build-t hello:1.0. 3. Place the image on all nodes
Then put this image on the master of K8s and two node. Here I will use it first.
Docker save hello:1.0 > hello.tar
The command gets the file hello.tar, and then passes hello.tar to the master of K8s and two node with the scp command.
Then on the master of K8s and two node, execute the following command to get the mirror hello:1.0
Docker load-I hello.tar
4. Deploy on kubernates
All right, after the above steps are completed, create the yaml file on the master of K8s
[root@localhost mjduan] # vi / data/mjduan/hello.yaml
The content of hello.yaml is as follows
ApiVersion: apps/v1beta2 kind: Deployment metadata: name: example-demo3 labels: app: example-demo3 spec: replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: example-demo3 template: metadata: labels: app: example-demo3 spec: containers:-name: example-demo3 # image name is our hello:1.0 image: hello:1.0 ports:-containerPort: 8080 protocol: TCP livenessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 30 timeoutSeconds: 30 imagePullPolicy: Never # Comment the following tolerations if Dashboard must not be deployed on master tolerations:-key: node-role.kubernetes.io/master effect: NoSchedule-apiVersion: v1 kind: Service metadata: name: example-demo3 labels: app: example-demo3 spec: ports:-port: 8080 targetPort: 8080 selector: app: example-demo3 type: NodePort
Deploy Docker image with the following command
[root@localhost mjduan] # kubectl create-f hello.yaml deployment.apps/example-demo3 created service/example-demo3 created
View pod information as follows
[root@localhost mjduan] # kubectl get pods NAME READY STATUS RESTARTS AGE example-demo3-746fc684df-h5dpq 1 746fc684df-h5dpq 1 Running 0 10s
Check the service, as shown below. The one with NAME of example-demo3 is the one we just deployed. The port mapping is 32300 of the host corresponds to 8080 of the container.
[root@localhost mjduan] # kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGE example-demo3 NodePort 10.107.189.127 8080:32300/TCP 1m kubernetes ClusterIP 10.96.0.1 443/TCP 2h
Access servic
[root@localhost mjduan] # curl http://k8s.master:32300 Hello, k8s! The above is how to deploy springboot in kubernates. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.