kubernetes集群已经部署好了,需要的话可以参考之前的文章https://www.cnblogs.com/winter1519/p/10015420.html
[root@master tomcat]# kubectl get nodes
NAME STATUS AGEnode1 Ready 10dnode2 Ready 10d部署nginx需要三个配置文件:
[root@master nginx]# vim nginx-pod.yaml
apiVersion: v1kind: Podmetadata: name: nginx-pod labels: name: nginx-podspec: containers: - name: nginx image: nginx ports: - containerPort: 80[root@master nginx]# vim nginx-rc.yaml
apiVersion: v1kind: ReplicationControllermetadata: name: nginx-rcspec: replicas: 2 selector: name: nginx-pod template: metadata: labels: name: nginx-pod spec: containers: - name: nginx-pod image: nginx ports: - containerPort: 80[root@master nginx]# vim nginx-pod.yaml
apiVersion: v1kind: Podmetadata: name: nginx-pod labels: name: nginx-podspec: containers: - name: nginx image: nginx ports: - containerPort: 80[root@master nginx]#kubectl create -f nginx-pod.yaml
[root@master nginx]#kubectl describe pod nginx[root@master nginx]#kubectl create -f nginx-rc.yaml[root@master nginx]#kubectl create -f nginx-service.yaml[root@master 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[root@master 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[root@master nginx]# kubectl get rcNAME DESIRED CURRENT READY AGEnginx-rc 2 2 2 1d访问nginx:http://192.168.91.26:30011http://192.168.91.27:30011
部署tomcat
[root@master tomcat]# vim tomcat-deployment.yaml
apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: my-tomcatspec: replicas: 2 template: metadata: labels: app: my-tomcat spec: containers: - name: my-tomcat image: docker.io/tomcat ports: - containerPort: 80 [root@master tomcat]# vim tomcat-service.yaml apiVersion: v1kind: Servicemetadata: name: my-tomcatspec: type: NodePort ports: - port: 8080 targetPort: 8080 nodePort: 31111 selector: app: my-tomcat
[root@master tomcat]# kubectl create -f tomcat-deployment.yaml
[root@master tomcat]# kubectl create -f tomcat-service.yaml[root@master tomcat]# kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEmy-tomcat 2 2 2 2 59m[root@master 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[root@master 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:31111http://192.168.91.27:31111