栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

资源定义haproxy

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

资源定义haproxy

资源定义haproxy
部署两个网站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.77



Welcome 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.77

It works!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/693246.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号