preface
1, this article took 4 to 5 days to finish 2, poking fun at yourself feel a bit stupid k8s network access that piece of card time is a bit long k8s under 3, continue to study under the network for this at the application level first chew TouTouDe 4, a responsible attitude Articles within each step are my own practice 5, original is not easy, please mercilessly forward to more people in need to see if I can have such an article for the first time, so it will not be so difficultCopy the code
Build the Nacos environment locally
Download code resources
https://gitee.com/pingfanrenbiji/nacos.git
Copy the code
Compile Nacos
mvn -Prelease-nacos clean install -U -Dmaven.test.skip=true
Copy the code
Start the Nacos
. / distribution/target/nacos - server - 1.3.0 - BETA/nacos/bin/startup. Sh -m standaloneCopy the code
Download the User and Order code resources
https://gitee.com/pingfanrenbiji/nacos-example.git
Copy the code
Starting the User service
Start the Order service
Viewing registration status
http://127.0.0.1:8848/nacos Copy the code
nacos/nacos
Verify that user can access order
Access localhost:8100/ k8S to view logsCopy the code
Docker-like order and User services
Generate jar packages for order and user, respectively
The directory structure is as follows
Create separate Dockerfile files
Generate the mirror
Sudo docker build-t user-image:v1.0. Sudo docker build-order :v1.0.Copy the code
Push the image to aliyun Docker library
- The url
https://cr.console.aliyun.com/cn-hangzhou/new
Copy the code
- Play tag
Sudo docker tag user - image: v1.0 registry.cn-shanghai.aliyuncs.com/mengfanxiao/user-image:v1.0Copy the code
Sudo docker tag order - image: v1.0 registry.cn-shanghai.aliyuncs.com/mengfanxiao/order-image:v1.0
- push
sudo docker push registry.cn-shanghai.aliyuncs.com/mengfanxiao/user-image
sudo docker push registry.cn-shanghai.aliyuncs.com/mengfanxiao/order-image
Copy the code
K8s deploys 2 Dockers
- Create a user. Yaml
- Create the order. Yaml
- The deployment of
kubectl apply -f user.yaml kubectl apply -f order.yaml Copy the code
- View the deployment Pods
kubectl get pods
Copy the code
kubectl get pods -o wide
Copy the code
Enter the cluster environment and check whether the PODS are accessible to each otherCopy the code
kubectl run busybox --rm=true --image=busybox --restart=Never -it
- Look at the service
kubectl get svc
Copy the code
- Check the ingress
kubectl get ingress
Copy the code
- Check to see if the User and Order services were successfully registered with NACOS
At this point, the user and server springboot projects run as pod and register with the nacOS service on the hostCopy the code
Problem assistance mode
- Check whether the Pod Docker Imags version number is correct
kubectl describe pods|grep user
Copy the code
- View pod Docker startup logs
kubectl logs -f order-65d5b4d858-rgnfs
Copy the code
- Check the port number mapping in k8S service startup files such as order.yaml
To be continued
- Order is accessed using service NodeType
- Access user via ingress nginx
- Test whether user can access order
Resource file
https://gitee.com/pingfanrenbiji/nacos-example.git
Relevant configuration files are also included
Copy the code
Refer to the article
https://www.cnblogs.com/wuzhenzhao/p/12076827.html
https://zhuanlan.zhihu.com/p/68700978
Copy the code
This article is formatted using MDNICE