先简单的做出两个运行httpd程序的pod,其中默认的index.html文件不一样
[root@master httpd]# vim Dockerfile
FROM busybox
RUN mkdir /data && \
echo "test page on jjyy" > /data/index.html
ENTRYPOINT ["/bin/httpd","-f","-h","/data"]
[root@master ~]# docker build -t 1314444/httpd:v0.1 httpd
[root@master ~]# vim httpd/Dockerfile
FROM busybox
RUN mkdir /data && \
echo "test page on 666" > /data/index.html
ENTRYPOINT ["/bin/httpd","-f","-h","/data"]
[root@master ~]# docker build -t 1314444/httpd:v0.2 httpd
web1
[root@master ~]# cat manifest/web1.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web1
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: web1
template:
metadata:
labels:
app: web1
spec:
containers:
- name: web1
image: 1314444/httpd:v0.1
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: web1
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: web1
type: NodePort
[root@master ~]# kubectl apply -f manifest/web1.yml
deployment.apps/web1 created
service/web1 created
[root@master ~]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/web1-855b788957-8fzpg 1/1 Running 0 17m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d9h
service/web1 NodePort 10.101.207.28 <none> 80:31807/TCP 17m
web2
[root@master ~]# cat manifest/web2.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web2
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: web2
template:
metadata:
labels:
app: web2
spec:
containers:
- name: httpd
image: 1314444/httpd:v0.2
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: web2
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: web2
type: NodePort
[root@master ~]# kubectl apply -f manifest/web2.yml
deployment.apps/web2 created
service/web2 created
[root@master ~]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/web1-855b788957-8fzpg 1/1 Running 0 17m
pod/web2-5f7456967b-t5vqs 1/1 Running 0 17m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d8h
service/web1 NodePort 10.101.207.28 <none> 80:31807/TCP 17m
service/web2 NodePort 10.100.246.130 <none> 80:31413/TCP 17m
haproxy
[root@master ~]# cat manifest/haproxy.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: haproxy
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: haproxy
template:
metadata:
labels:
app: haproxy
spec:
containers:
- image: 1314444/haproxy:v0.3
imagePullPolicy: IfNotPresent
name: haproxy
env:
- name: RSIP
value: "10.101.207.28 10.100.246.130"
---
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 apply -f manifest/haproxy.yml
deployment.apps/haproxy created
[root@master ~]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/haproxy-54c76db7b8-bl44g 1/1 Running 0 111s
pod/web1-855b788957-8fzpg 1/1 Running 0 17m
pod/web2-5f7456967b-t5vqs 1/1 Running 0 17m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/haproxy NodePort 10.101.200.144 <none> 80:30311/TCP 13m
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d9h
service/web1 NodePort 10.101.207.28 <none> 80:31807/TCP 17m
service/web2 NodePort 10.100.246.130 <none> 80:31413/TCP 17m
测试
[root@master ~]# curl 10.101.207.28
test page on jjyy
[root@master ~]# curl 10.100.246.130
test page on 666
[root@master ~]# curl 10.101.200.144
test page on jjyy
[root@master ~]# curl 10.101.200.144
test page on 666
[root@master ~]# curl 10.101.200.144
test page on jjyy
[root@master ~]# curl 10.101.200.144
test page on 666


