背景:
阅读新闻
Kubernetes部署Nginx/Tomcat
[日期:2019-07-24] 来源:Linux社区 作者:winter1519 [字体:]
kubernetes集群已经部署好了,需要的话可以参考之前的文章 https://www.linuxidc.com/Linux/2019-07/159548.htm
[root@master tomcat]# kubectl get nodes
NAME STATUS AGE
node1 Ready 10d
node2 Ready 10d
部署nginx
需要三个配置文件:
[root@master nginx]# vim nginx-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
[root@master nginx]# vim nginx-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-rc
spec:
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: v1
kind: Pod
metadata:
name: nginx-pod
labels:
name: nginx-pod
spec:
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 wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx-pod 1/1 Running 1 1d 10.255.95.2 node2
nginx-rc-351xd 1/1 Running 1 1d 10.255.1.3 node1
[root@master nginx]# kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.254.0.1 <none> 443/TCP 10d
nginx-service 10.254.208.231 <nodes> 80:30011/TCP 1d
[root@master nginx]# kubectl get rc
NAME DESIRED CURRENT READY AGE
nginx-rc 2 2 2 1d
访问nginx:
:30011
:30011
部署tomcat
[root@master tomcat]# vim tomcat-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-tomcat
spec:
replicas: 2
template:
metadata:
labels:
app: my-tomcat
spec:
containers:
- name: my-tomcat
image: docker.io/tomcat
ports:
- containerPort: 80