一、准备条件
1) 确保kubernetes可以访问:reg.yunwei.edu镜像库(vim /etc/hosts)
[root@cicd yml]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.254.20 reg.yunwei.edu #192.168.253.9 reg.yunwei.edu 192.168.253.9 cicd 192.168.253.14 node1 192.168.253.11 node2 192.168.253.10 node3
2) 然后创建sock-shop的名称空间。
kubectl create namespace sock-shop
[root@cicd yml]# kubectl get ns NAME STATUS AGE default Active 3d kube-public Active 3d kube-system Active 3d sock-shop Active 3h weave Active 2h
3) 需要准备镜像:
4) 然后进入sock-shop目录下下载所需镜像到sock-shop命名空间。
[root@cicd yml]# cd /root/kubernetes/sock-shop/ [root@cicd sock-shop]# ls complete-demo.yaml
二、部署微服务
编辑complete-demo.yaml后,执行
kubectl apply -f complete-demo.yaml
查看前端service的访问端口:
kubectl get pod -n sock-shop
kubectl get service -n sock-shop
[root@cicd sock-shop]# kubectl get pod -n sock-shop sock-shop内pod状态 NAME READY STATUS RESTARTS AGE carts-5486c9cc4f-k9j4p 1/1 Running 0 2h carts-db-56ffbd7b87-rlkkg 1/1 Running 0 2h catalogue-68bd49fd6d-s484q 1/1 Running 0 2h catalogue-db-867b859dd5-5cdwv 1/1 Running 0 2h front-end-868c9c5965-xjvcr 1/1 Running 0 2h orders-56dd9f89d8-5jcmx 1/1 Running 0 2h orders-db-677c4864ff-mdqp8 1/1 Running 0 2h payment-6548fcccc8-vlhds 1/1 Running 0 2h queue-master-7d7dd4bd9b-lbvmv 1/1 Running 0 2h rabbitmq-74cc7558bc-c44ln 1/1 Running 0 2h shipping-9f757f4f8-2nrq7 1/1 Running 0 2h user-5d5b5c655f-2n47l 1/1 Running 0 2h user-db-99f788995-xglhz 1/1 Running 1 2h [root@cicd sock-shop]# kubectl get svc -n sock-shop #sock-shop内svc状态 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE carts ClusterIP 10.68.221.36 <none> 80/TCP 2h carts-db ClusterIP 10.68.165.206 <none> 27017/TCP 2h catalogue ClusterIP 10.68.143.207 <none> 80/TCP 2h catalogue-db ClusterIP 10.68.70.95 <none> 3306/TCP 2h front-end NodePort 10.68.128.49 <none> 80:30001/TCP 2h orders ClusterIP 10.68.155.168 <none> 80/TCP 2h orders-db ClusterIP 10.68.56.165 <none> 27017/TCP 2h payment ClusterIP 10.68.83.6 <none> 80/TCP 2h queue-master ClusterIP 10.68.255.236 <none> 80/TCP 2h rabbitmq ClusterIP 10.68.16.109 <none> 5672/TCP 2h shipping ClusterIP 10.68.185.79 <none> 80/TCP 2h user ClusterIP 10.68.1.194 <none> 80/TCP 2h user-db ClusterIP 10.68.31.241 <none> 27017/TCP 2h
三、登录浏览器验证(集群节点ip+端口:192.168.253.10:30001)