如何解决无法公开部署 kubernetes 信息中心 (HTTPS) 我目前拥有的我想要什么
我是 kubernetes 的新手,经过长时间的研究,似乎我的资源快用完了,所以如果有人能帮助我,我会非常高兴。
我目前拥有的
- 我通过 SSH 连接的一个节点,裸机 kubernetes 设置(注意我未在云中运行 k8s)
-
kubectl version
在客户端和服务器端产生1.20
- Nginx 入口控制器
- 使用 kubeadm 设置集群
- 以下 Pod、服务和一个入口资源(仪表板):
豆荚:
命名空间 | 姓名 | 准备好 | 状态 | 重启 | 年龄 |
---|---|---|---|---|---|
入口-Nginx | ingress-Nginx-admission-create-4ml4p | 0/1 | 已完成 | 0 | 23 米 |
入口-Nginx | ingress-Nginx-admission-patch-jj9c6 | 0/1 | 已完成 | 1 | 23 米 |
入口-Nginx | ingress-Nginx-controller-67897c9494-kxwgv | 1/1 | 运行 | 0 | 23 米 |
kube 系统 | coredns-74ff55c5b-2xbvq | 1/1 | 运行 | 0 | 23 米 |
kube 系统 | coredns-74ff55c5b-sc667 | 1/1 | 运行 | 0 | 23 米 |
kube 系统 | etcd-k8s.mydomain.de | 1/1 | 运行 | 0 | 23 米 |
kube 系统 | kube-apiserver-k8s.mydomain.de | 1/1 | 运行 | 0 | 23 米 |
kube 系统 | kube-controller-manager-k8s.mydomain.de | 1/1 | 运行 | 0 | 23 米 |
kube 系统 | kube-flannel-ds-fhzzp | 1/1 | 运行 | 0 | 23 米 |
kube 系统 | kube-proxy-lq7tt | 1/1 | 运行 | 0 | 23 米 |
kube 系统 | kube-scheduler-k8s.mydomain.de | 1/1 | 运行 | 0 | 23 米 |
kubernetes-dashboard | dashboard-metrics-scraper-7b59f7d4df-v6qsn | 1/1 | 运行 | 0 | 23 米 |
kubernetes-dashboard | kubernetes-dashboard-74d688b6bc-5x4nd | 1/1 | 运行 | 0 | 23 米 |
服务:
命名空间 | 姓名 | 类型 | CLUSTER-IP | 外部IP | 端口 | 年龄 |
---|---|---|---|---|---|---|
默认 | kubernetes | 集群IP | 10.96.0.1 | 无 | 443/TCP | 33d |
入口-Nginx | 入口-Nginx-控制器 | 节点端口 | 10.98.67.34 | 无 | 80:32346/TCP、443:30710/TCP | 33d |
入口-Nginx | ingress-Nginx-controller-admission | 集群IP | 10.110.196.58 | 无 | 443/TCP | 33d |
kube 系统 | kube-dns | 集群IP | 10.96.0.10 | 无 | 53/UDP、53/TCP、9153/TCP | 33d |
kubernetes-dashboard | dashboard-metrics-scraper | 集群IP | 10.109.128.22 | 无 | 8000/TCP | 33d |
kubernetes-dashboard | kubernetes-dashboard | 集群IP | 10.98.158.159 | 无 | 443/TCP | 33d |
入口资源(仪表板):
命名空间 | 姓名 | 类 | 主机 | 地址 | 端口 | 年龄 |
---|---|---|---|---|---|---|
kubernetes-dashboard | 仪表板入口 | dashboard.k8s.mydomain.de | 10.10.1.164 | 80 | 52m |
当我尝试使用 https://dashboard.k8s.mydomain.de
访问 kubernetes 仪表板时,没有任何反应。当我尝试使用 https://dashboard.k8s.mydomain.de:30710
访问它时,它是 Nginx 入口控制器的 HTTPS TCP 端口,然后它就可以工作了。它是一个不安全的连接,浏览器会警告我,但它可以工作。但显然这不是我们想要的行为。
我想要什么
我想以某种方式部署 kubernetes 仪表板,以便 https://dashboard.k8s.mydomain.de
允许通过 HTTPS 访问 kubernetes 仪表板。我不知道为什么目前情况并非如此。
-
Nginx 入口控制器:https://github.com/kubernetes/ingress-nginx/blob/master/deploy/static/provider/baremetal/deploy.yaml
-
Kubernetes 仪表板:https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
-
仪表板入口资源:
apiVersion: networking.k8s.io/v1
kind: Ingress
Metadata:
name: dashboard-ingress
namespace: kubernetes-dashboard
annotations:
Nginx.ingress.kubernetes.io/backend-protocol: HTTPS
spec:
rules:
- host: dashboard.k8s.mydomain.de
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: kubernetes-dashboard
port:
number: 443
Nginx入口控制器的日志告诉我它注册了入口资源,所以我很困惑:
Nginx Ingress controller
Release: v0.44.0
Build: f802554ccfadf828f7eb6d3f9a9333686706d613
Repository: https://github.com/kubernetes/ingress-Nginx
Nginx version: Nginx/1.19.6
I0323 09:42:57.665847 6 flags.go:208] "Watching for Ingress" class="Nginx"
W0323 09:42:57.665953 6 flags.go:213] Ingresses with an empty class will also be processed by this Ingress controller
-------------------------------------------------------------------------------
W0323 09:42:57.667132 6 client_config.go:614] Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.
I0323 09:42:57.667958 6 main.go:241] "Creating API client" host="https://10.96.0.1:443"
I0323 09:42:57.682847 6 main.go:285] "Running in Kubernetes cluster" major="1" minor="20" git="v1.20.3" state="clean" commit="01849e73f3c86211f05533c2e807736e776fcf29" platform="linux/amd64"
I0323 09:42:57.997597 6 main.go:105] "SSL fake certificate created" file="/etc/ingress-controller/ssl/default-fake-certificate.pem"
I0323 09:42:58.003204 6 main.go:115] "Enabling new Ingress features available since Kubernetes v1.18"
W0323 09:42:58.008105 6 main.go:127] No IngressClass resource with name Nginx found. Only annotation will be used.
I0323 09:42:58.033445 6 ssl.go:532] "loading tls certificate" path="/usr/local/certificates/cert" key="/usr/local/certificates/key"
I0323 09:42:58.070414 6 Nginx.go:254] "Starting Nginx Ingress controller"
I0323 09:42:58.077773 6 event.go:282] Event(v1.ObjectReference{Kind:"ConfigMap",Namespace:"ingress-Nginx",Name:"ingress-Nginx-controller",UID:"a76c1e40-f5aa-4353-aeea-35bccbbb57a7",APIVersion:"v1",ResourceVersion:"3497961",Fieldpath:""}): type: 'normal' reason: 'CREATE' ConfigMap ingress-Nginx/ingress-Nginx-controller
I0323 09:42:59.183747 6 event.go:282] Event(v1.ObjectReference{Kind:"Ingress",Namespace:"kubernetes-dashboard",Name:"dashboard-ingress",UID:"6f02c931-bfad-44a1-a219-4e2b2970365e",APIVersion:"networking.k8s.io/v1beta1",ResourceVersion:"3497191",Fieldpath:""}): type: 'normal' reason: 'Sync' Scheduled for sync
I0323 09:42:59.271684 6 Nginx.go:296] "Starting Nginx process"
I0323 09:42:59.271826 6 leaderelection.go:243] attempting to acquire leader lease ingress-Nginx/ingress-controller-leader-Nginx...
I0323 09:42:59.272447 6 Nginx.go:316] "Starting validation webhook" address=":8443" certPath="/usr/local/certificates/cert" keyPath="/usr/local/certificates/key"
I0323 09:42:59.272851 6 controller.go:146] "Configuration changes detected,backend reload required"
I0323 09:42:59.288414 6 leaderelection.go:253] successfully acquired lease ingress-Nginx/ingress-controller-leader-Nginx
I0323 09:42:59.288501 6 status.go:84] "New leader elected" identity="ingress-Nginx-controller-67897c9494-kxwgv"
I0323 09:42:59.302119 6 status.go:201] "POD is not ready" pod="ingress-Nginx/ingress-Nginx-controller-67897c9494-kxwgv" node="k8s.mydomain.de"
I0323 09:42:59.307191 6 status.go:281] "updating Ingress status" namespace="kubernetes-dashboard" ingress="dashboard-ingress" currentValue=[{IP:10.10.1.164 Hostname: Ports:[]}] newValue=[]
I0323 09:42:59.315053 6 event.go:282] Event(v1.ObjectReference{Kind:"Ingress",ResourceVersion:"3498054",Fieldpath:""}): type: 'normal' reason: 'Sync' Scheduled for sync
I0323 09:42:59.381846 6 controller.go:163] "Backend successfully reloaded"
I0323 09:42:59.382014 6 controller.go:174] "Initial sync,sleeping for 1 second"
I0323 09:42:59.382266 6 event.go:282] Event(v1.ObjectReference{Kind:"Pod",Name:"ingress-Nginx-controller-67897c9494-kxwgv",UID:"2ba6f14e-36a8-401b-a1d8-00921cbe9604",ResourceVersion:"3497997",Fieldpath:""}): type: 'normal' reason: 'RELOAD' Nginx reload triggered due to a change in configuration
I0323 09:43:59.323910 6 status.go:281] "updating Ingress status" namespace="kubernetes-dashboard" ingress="dashboard-ingress" currentValue=[] newValue=[{IP:10.10.1.164 Hostname: Ports:[]}]
I0323 09:43:59.333091 6 event.go:282] Event(v1.ObjectReference{Kind:"Ingress",ResourceVersion:"3498144",Fieldpath:""}): type: 'normal' reason: 'Sync' Scheduled for sync
当我使用 microk8s 而不是 kubeadm 设置集群时,它可以工作。 请说明我必须做什么才能完成这项工作。
提前致谢
解决方法
请在hostNetwork模式下运行nginx入口控制器https://kubernetes.github.io/ingress-nginx/deploy/baremetal/#via-the-host-network
template:
spec:
hostNetwork: true
并将其作为 DaemonSet 运行。
并将 dnsPolicy 设置为 ClusterFirstWithHostNet
另外,请阅读https://kubernetes.github.io/ingress-nginx/deploy/baremetal/#via-the-host-network
中的安全警告如果您使用的是 https://kubernetes.github.io/ingress-nginx/deploy/#using-helm,请在值文件中添加以下内容
controller:
dnsPolicy: ClusterFirstWithHostNet
hostNetwork: true
kind: DaemonSet
,
我不确定您在入口资源位置实际得到了什么:
dashboard.k8s.mydomain.de
除此之外,在您的服务中:ingress-nginx-controller
公开为 NodePort
,它应该公开为 LoadBalancer
,以便您可以获得一个 IP。
您可以将该 IP 作为 A 记录添加到 DNS 中并映射域。在 Ingress 中,您可以添加与您相同的域。
现在,对于 HTTPS,您可能必须在 secret
中创建和存储证书,以便 Nginx 入口可以使用证书并通过 HTTPS 服务流量。
如果您使用 cert-manager 自动管理 TLS/SSL 证书,您的入口将是这样的:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
cert-manager.io/cluster-issuer: dev
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-body-size: 50m
nginx.ingress.kubernetes.io/proxy-read-timeout: "2000"
nginx.ingress.kubernetes.io/proxy-send-timeout: "2000"
nginx.ingress.kubernetes.io/rewrite-target: /
name: dev-ingress
spec:
rules:
- host: dev.example.io
http:
paths:
- backend:
serviceName: service
servicePort: 80
tls:
- hosts:
- dev.example.io
secretName: dev
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。