|
2019-05-17
创建一个configmap配置default.conf文件用来转发TPS的thanos query查询地址,注意proxy_pass后面填写自己实际的内网查询地址,下一步挂载这个configmap到pod里面即可
apiVersion: v1 data: default.conf: |- server { listen 80; listen [::]:80; server_name localhost; #access_log /var/log/nginx/host.access.log main; location / { proxy_pass http://10.0.0.234:9090/; proxy_set_header X-Real-IP $remote_addr; client_max_body_size 1000m; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } kind: ConfigMap metadata: name: nginx-cm namespace: monitor
创建一个nginx的工作负载,然后将上一步的配置挂载到容器的default.conf文件。
apiVersion: apps/v1 kind: Deployment metadata: labels: k8s-app: tps-thanos-nginx qcloud-app: tps-thanos-nginx name: tps-thanos-nginx namespace: monitor spec: replicas: 1 selector: matchLabels: k8s-app: tps-thanos-nginx qcloud-app: tps-thanos-nginx strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: k8s-app: tps-thanos-nginx qcloud-app: tps-thanos-nginx spec: containers: - image: nginx imagePullPolicy: Always name: tps-thanos-nginx resources: limits: cpu: 500m memory: 1Gi requests: cpu: 250m memory: 256Mi securityContext: privileged: false volumeMounts: - mountPath: /etc/nginx/conf.d/default.conf name: vol subPath: default.conf dnsPolicy: ClusterFirst imagePullSecrets: - name: qcloudregistrykey restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 volumes: - configMap: defaultMode: 420 name: nginx-cm name: vol
创建servic绑定后端的workload,如果不想花钱买公网的clb,可以用nodeport类型的svc,通过节点公网ip和nodeport访问。
apiVersion: v1 kind: Service metadata: name: tps-thanos-nginx namespace: monitor spec: externalTrafficPolicy: Cluster ports: - name: 80-80-tcp nodePort: 31642 port: 80 protocol: TCP targetPort: 80 selector: k8s-app: tps-thanos-nginx qcloud-app: tps-thanos-nginx sessionAffinity: None type: LoadBalancer
如果集群部署了nginx-ingress,也可以用nginx-ingress来暴露一个域名来访问,当然也可以用tke提供的负载均衡类型ingress暴露域名提供访问。
apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: annotations: kubernetes.io/ingress.class: ingress name: tps-thanos-ingress namespace: monitor spec: rules: - host: tps-thanos.tke.niewx.cn http: paths: - backend: serviceName: tps-thanos-nginx servicePort: 80 path: /
浏览器输入公网clb的vip访问TPS的prometheus数据查询地址
浏览器输入节点公网ip和nodeport访问TPS的prometheus数据查询地址
浏览器域名访问TPS的prometheus数据查询地址
编辑:航网科技 来源:腾讯云 本文版权归原作者所有 转载请注明出处
微信扫一扫咨询客服
全国免费服务热线
0755-36300002