//创建两个pod
[root@master ~]# mkdir httpd1
[root@master ~]# cd httpd1/
[root@master httpd1]# vim dockerfile
[root@master httpd1]# cat dockerfile 
FROM busybox
  
RUN mkdir /data && echo 'httpd1' > /data/index.html

CMD ["/bin/httpd","-f","-h","/data"]
[root@master httpd1]# docker build -t wssswsss/httpd1:v1.0 .
Sending build context to Docker daemon  2.048kB
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 'httpd1' > /data/index.html
 ---> Running in 84db10dc3565
Removing intermediate container 84db10dc3565
 ---> fddb1ee26b3c
Step 3/3 : CMD ["/bin/httpd","-f","-h","/data"]
 ---> Running in b2c16f44571a
Removing intermediate container b2c16f44571a
 ---> 7aeb28a25ca2
Successfully built 7aeb28a25ca2
Successfully tagged wssswsss/httpd1:v1.0
[root@master httpd1]# mkdir httpd2
[root@master httpd1]# cd httpd2/
[root@master httpd2]# vim dockerfile
[root@master httpd2]# cat dockerfile 
FROM busybox
  
RUN mkdir /data && echo 'httpd2' > /data/index.html

CMD ["/bin/httpd","-f","-h","/data"]
[root@master httpd2]# docker build -t wssswsss/httpd2:v1.0 .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM busybox
 ---> ffe9d497c324
Step 2/3 : RUN mkdir /data && echo 'httpd2' > /data/index.html
 ---> Running in f93a87fdf75f
Removing intermediate container f93a87fdf75f
 ---> 27ea6c14b87e
Step 3/3 : CMD ["/bin/httpd","-f","-h","/data"]
 ---> Running in d6421ba5904f
Removing intermediate container d6421ba5904f
 ---> 2d8ab5bd79f9
Successfully built 2d8ab5bd79f9
Successfully tagged wssswsss/httpd2:v1.0
[root@master httpd2]# mkdir haproxy
[root@master httpd2]# cd haproxy/
[root@master haproxy]# vim httpd1.yml
[root@master haproxy]# cat httpd1.yml 
---
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: wssswsss/httpd1:v1.0
        name: httpd1        
---
apiVersion: v1
kind: Service
metadata:
  name: httpd1
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: httpd1

[root@master haproxy]# kubectl create -f httpd1.yaml
deployment.apps/httpd1 created
service/httpd1 created
//创建两个service
[root@master haproxy]# vim 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: wssswsss/httpd1:v1.0
        name: httpd1        
---
apiVersion: v1
kind: Service
metadata:
  name: httpd1
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: httpd1
    
[root@master haproxy]# kubectl create -f httpd1.yaml
deployment.apps/httpd1 created
service/httpd1 created
[root@master haproxy]# 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: wssswsss/httpd2:v1.0
        name: httpd2
---
apiVersion: v1
kind: Service
metadata:
  name: httpd2
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: httpd2

[root@master haproxy]# kubectl create -f httpd2.yaml
deployment.apps/httpd2 created
service/httpd2 created
[root@master haproxy]# kubectl get pod,svc
NAME                         READY   STATUS             RESTARTS   AGE
pod/httpd1-hjicd6kl-ib9be   1/1     Running   0                    18s
pod/httpd2-cb86545b-9xbfr    0/1     ImagePullBackOff   0          68s
pod/nginx-6799fc88d8-2kpth   1/1     Running            0          3d17h

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/httpd1       ClusterIP   10.102.55.13    <none>        80/TCP    8s
service/httpd2       ClusterIP   10.98.155.38     <none>        80/TCP         68s
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        3d18h
service/nginx        NodePort    10.104.160.232   <none>        80:31085/TCP   3d17h
[root@master haproxy]# 
//创建haproxy
[root@master haproxy]# vi haproxy.yaml 
[root@master haproxy]# cat haproxy.yaml 
---
apiVersion: apps/v1
kind: deployment
metadata:
  labels:
    app: haproxy
    name: haproxy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: haproxy
  template:
    metadate:
      labels:
        app: haproxy
    spec:
      containers:
      - image: wssswsss/haproxy:v1.0
        name: haproxy
        env:
        - name: RSIP
          value: "10.102.55.13 10.98.155.38"
---
apiVersion: v1
kind: Service
metadata:
  name: haproxy
spec:
  ports:
  - port: 80
    target: 80
  selector:
    app: haproxy
  type: NodePort


[root@master haproxy]# 
[root@master haproxy]# kubectl get pod,svc
NAME                         READY   STATUS             RESTARTS   AGE
pod/haproxy-8757fcf5-dv4d   1/1     Running   0         0          1m25s
pod/httpd1-hjicd6kl-ib9be   1/1     Running   0                    18s
pod/httpd2-cb86545b-9xbfr    0/1     ImagePullBackOff   0          68s
pod/nginx-6799fc88d8-2kpth   1/1     Running            0          3d17h

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
pod/haproxy-8757fcf5-dv4d   1/1  10.107.15.102  .<none>        80:31089/TCP   2m23s
service/httpd1       ClusterIP   10.102.55.13    <none>        80/TCP    8s
service/httpd2       ClusterIP   10.98.155.38    <none>        80/TCP         68s
service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        3d18h
service/nginx        NodePort    10.104.160.232  <none>        80:31085/TCP   3d17h
[root@master haproxy]#

测试

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐