编写测试web镜像
[root@master ~]# cat Dockerfile
FROM busybox
RUN mkdir /data && echo 'hello,this is a xaw' > /data/index.html
CMD ["/bin/httpd","-f","-h","/data"]
[root@master ~]# docker build -t my922/apache:v1.0 .
Sending build context to Docker daemon 3.486MB
Step 1/3 : FROM busybox
latest: Pulling from library/busybox
3cb635b06aa2: Pull complete
Digest: sha256:b5cfd4befc119a590ca1a81d6bb0fa1fb19f1fbebd0397f25fae164abe1e8a6a
Status: Downloaded newer image for busybox:latest
---> ffe9d497c324
Step 2/3 : RUN mkdir /data && echo 'hello,this is a xaw' > /data/index.html
---> Running in c7d3780508ae
Removing intermediate container c7d3780508ae
---> 6ad4398c8f56
Step 3/3 : CMD ["/bin/httpd","-f","-h","/data"]
---> Running in c91474156b62
Removing intermediate container c91474156b62
---> ed997eb4e1b8
Successfully built ed997eb4e1b8
Successfully tagged my922/apache:v1.0
[root@master apache]# cat Dockerfile
FROM busybox
RUN mkdir /data && echo 'hello,this is a my' > /data/index.html
CMD ["/bin/httpd","-f","-h","/data"]
[root@master apache]# docker build -t my922/apache:v2.0 .
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM busybox
---> ffe9d497c324
Step 2/3 : RUN mkdir /data && echo 'hello,this is a my' > /data/index.html
---> Running in e679e19f3f83
Removing intermediate container e679e19f3f83
---> b696232ef844
Step 3/3 : CMD ["/bin/httpd","-f","-h","/data"]
---> Running in 7a77d317fdba
Removing intermediate container 7a77d317fdba
---> e36c29e6c5d1
Successfully built e36c29e6c5d1
Successfully tagged my922/apache:v2.0
用这两个镜像做出两个pod并做出两个service
[root@master ~]# cat httpd1.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: httpd1
name: httpd1
spec:
replicas: 1
selector:
matchLabels:
app: httpd1
template:
metadata:
labels:
app: httpd1
spec:
containers:
- image: my922/apache:v1.0
name: httpd1
---
apiVersion: v1
kind: Service
metadata:
name: httpd1
spec:
ports:
- port: 80
targetPort: 80
selector:
app: httpd1
[root@master ~]# kubectl create -f httpd1.yaml
deployment.apps/httpd1 created
service/httpd1 created
[root@master ~]# cat httpd2.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: httpd2
name: httpd2
spec:
replicas: 1
selector:
matchLabels:
app: httpd2
template:
metadata:
labels:
app: httpd2
spec:
containers:
- image: my922/apache:v2.0
name: httpd2
---
apiVersion: v1
kind: Service
metadata:
name: httpd2
spec:
ports:
- port: 80
targetPort: 80
selector:
app: httpd2
[root@master ~]# kubectl create -f httpd2.yaml
deployment.apps/httpd2 created
service/httpd2 created
查看创建的deployment以及service
[root@master ~]# kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/httpd1-7c658c599f-prxkp 0/1 ContainerCreating 0 19s
pod/httpd2-679cf98bc8-nvls7 0/1 ContainerCreating 0 14s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/httpd1 ClusterIP 10.107.38.25 <none> 80/TCP 19s
service/httpd2 ClusterIP 10.97.201.78 <none> 80/TCP 14s
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 21h
编写写资源清单定义haproxy
[root@master ~]# cat haproxy.yaml
piVersion: apps/v1
kind: Deployment
metadata:
name: haproxy
namespace: default
labels:
app: haproxy
spec:
selector:
matchLabels:
app: haproxy
template:
metadata:
labels:
app: haproxy
spec:
containers:
- image: my922/haproxy:latest
imagePullPolicy: IfNotPresent
name: haproxy
env:
- name: RSIP
value: "10.107.38.25 10.97.201.78 "
---
apiVersion: v1
kind: Service
metadata:
name: haproxy
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: haproxy
type: NodePort
[root@master ~]# kubectl apply -f haproxy.yml
deployment.apps/haproxy created
service/haproxy created
测试