Kubernetes部署Nginx/Tomcat

kubernetes集群已经部署好了,需要的话可以参考之前的文章 http://www.info110.com/Linux/2019-07/159548.htm

[[email protected] tomcat]# kubectl get nodesNAME      STATUS    AGEnode1    Ready    10dnode2    Ready    10d部署nginx

需要三个配置文件:

[[email protected] nginx]# vim nginx-pod.yamlapiVersion: v1kind: Podmetadata:name: nginx-podlabels:name: nginx-podspec:containers:– name: nginximage: nginxports:– containerPort: 80

[[email protected] nginx]# vim nginx-rc.yamlapiVersion: v1kind: ReplicationControllermetadata:name: nginx-rcspec:replicas: 2selector:name: nginx-podtemplate:metadata:labels:name: nginx-podspec:containers:– name: nginx-podimage: nginxports:– containerPort: 80

[[email protected] nginx]# vim nginx-pod.yamlapiVersion: v1kind: Podmetadata:name: nginx-podlabels:name: nginx-podspec:containers:– name: nginximage: nginxports:– containerPort: 80

[[email protected] nginx]#kubectl create -f nginx-pod.yaml[[email protected] nginx]#kubectl describe pod nginx[[email protected] nginx]#kubectl create -f  nginx-rc.yaml[[email protected] nginx]#kubectl create -f  nginx-service.yaml[[email protected] nginx]# kubectl get pods -o wideNAME                        READY    STATUS    RESTARTS  AGE      IP            NODEnginx-pod                  1/1      Running  1          1d        10.255.95.2  node2nginx-rc-351xd              1/1      Running  1          1d        10.255.1.3    node1[[email protected] nginx]# kubectl get svcNAME            CLUSTER-IP      EXTERNAL-IP  PORT(S)          AGEkubernetes      10.254.0.1      <none>        443/TCP          10dnginx-service  10.254.208.231  <nodes>      80:30011/TCP    1d[[email protected] nginx]# kubectl get rcNAME      DESIRED  CURRENT  READY    AGEnginx-rc  2        2        2        1d访问nginx:http://192.168.91.26:30011

http://192.168.91.27:30011

 

部署tomcat

[[email protected] tomcat]# vim tomcat-deployment.yamlapiVersion: extensions/v1beta1kind: Deploymentmetadata:name: my-tomcatspec:replicas: 2template:metadata:labels:app: my-tomcatspec:containers:– name: my-tomcatimage: docker.io/tomcatports:– containerPort: 80

[[email protected] tomcat]# vim tomcat-service.yamlapiVersion: v1kind: Servicemetadata:name: my-tomcatspec:type: NodePortports:– port: 8080targetPort: 8080nodePort: 31111selector:app: my-tomcat

[[email protected] tomcat]# kubectl create -f tomcat-deployment.yaml[[email protected] tomcat]# kubectl create -f tomcat-service.yaml

[[email protected] tomcat]# kubectl get deploymentNAME        DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGEmy-tomcat  2        2        2            2          59m[[email protected] tomcat]# kubectl get svcNAME            CLUSTER-IP      EXTERNAL-IP  PORT(S)          AGEkubernetes      10.254.0.1      <none>        443/TCP          10dmy-tomcat      10.254.110.240  <nodes>      8080:31111/TCP  59mnginx-service  10.254.208.231  <nodes>      80:30011/TCP    1d[[email protected] tomcat]# kubectl get pods -o wideNAME                        READY    STATUS    RESTARTS  AGE      IP            NODEmy-tomcat-464109745-ctmdf  1/1      Running  0          1h        10.255.1.5    node1my-tomcat-464109745-wmxpz  1/1      Running  0          1h        10.255.95.4  node2nginx-pod                  1/1      Running  1          1d        10.255.95.2  node2nginx-rc-351xd              1/1      Running  1          1d        10.255.1.3    node1访问tomcathttp://192.168.91.26:31111

http://192.168.91.27:31111

郑重声明:本网站发布的内容(图片、视频和文字)以及用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注