部署两个网站pod
//nginx
[root@master ~]# cat nginx.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: NodePort
//httpd
[root@master ~]# cat httpd.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: httpd
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: httpd
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: httpd
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: httpd
type: NodePort
//创建
[root@master ~]# kubectl apply -f nginx.yaml
deployment.apps/nginx created
service/nginx created
[root@master ~]# kubectl apply -f httpd.yml
deployment.apps/httpd created
service/httpd created
//查看
[root@master ~]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/httpd-66dd47b7cd-9m6mb 0/1 ContainerCreating 0 10s
pod/nginx-7cf7d6dbc8-nfq6l 1/1 Running 0 65s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/httpd NodePort 10.99.197.72 80:31467/TCP 10s
service/kubernetes ClusterIP 10.96.0.1 443/TCP 64m
service/nginx NodePort 10.96.217.207 80:32306/TCP 65s
haproxy
[root@master ~]# cat haproxy.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: haproxy
namespace: default
spec:
restartPolicy: onFailure
containers:
- image: 1968046xux/haproxy:v1
imagePullPolicy: IfNotPresent
name: haproxy
env:
- name: RSs
value: "nginx httpd"
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 20
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 20
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: haproxy
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: haproxy
type: NodePort
//创建
[root@master ~]# kubectl create -f haproxy.yaml
deployment.apps/haproxy created
service/haproxy created
//查看
[root@master ~]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/haproxy-594d954b8c-cq4v4 0/1 ContainerCreating 0 8s
pod/httpd-66dd47b7cd-9m6mb 1/1 Running 0 5m25s
pod/nginx-7cf7d6dbc8-nfq6l 1/1 Running 0 6m20s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/haproxy NodePort 10.104.137.77 80:31685/TCP 7s
service/httpd NodePort 10.99.197.72 80:31467/TCP 5m25s
service/kubernetes ClusterIP 10.96.0.1 443/TCP 69m
service/nginx NodePort 10.96.217.207 80:32306/TCP 6m20s
测试
[root@master ~]# curl 10.104.137.77Welcome to nginx! Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.
[root@master ~]# curl 10.104.137.77It works!



