第一步,创建deploy
apiVersion: extensions/v1beta1 #k8s版本不同,api可能也不同 kind: Deployment Metadata: name: myNginx namespace: default spec: replicas: 1 selector: matchLabels: app: Nginx template: Metadata: name: web labels: app: Nginx spec: containers: - name: Nginx image: Nginx ports: - name: Nginx containerPort: 80 volumeMounts: - name: html-config mountPath: /etc/Nginx/conf.d/Nginx.conf subPath: Nginx.conf readOnly: true - name: nginx-logs mountPath: /var/log/Nginx/ volumes: - name: html-config configMap: name: Nginx.conf - name: nginx-logs hostPath: path: /test-Nginx/logs/
kubectl create cm Nginx.conf --from-file=./Nginx.conf
server{ listen 80; server_name test-Nginx.test.net; access_log /var/log/Nginx/access.log main; error_log /var/log/Nginx/error.log error; location / { return 200; } }
3.创建ingress,使Nginx可以通过域名访问
apiVersion: extensions/v1beta1 #k8s版本不同,api可能也不同 kind: Ingress Metadata: name: test-Nginx namespace: default spec: rules: - host: test-Nginx.test.net #域名 http: paths: - backend: serviceName: service-Nginx #关联后端的svc servicePort: 80 #svc的端口号 status: loadBalancer: ingress: - ip: xxx.xxx.xxx.xxx #阿里云的k8s的负载均衡地址
4.添加阿里云dns域名解析
5.现在就可以在外放访问域名了
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。