ubuntu Microk8s入口未重定向至pod

qc6wkl3g  于 2023-11-17  发布在  其他
关注(0)|答案(1)|浏览(129)

我第一次尝试设置kubernetes,可能是一些愚蠢的事情。所以我有一个Ubuntu服务器,最近安装了microk 8 s,我正在尝试使用nginx为一个应用程序设置部署。我已经成功启动了上述部署,我可以直接从服务器的ssh连接到它。还有一个入口控制器与应用程序的命名空间不同。当我试图通过浏览器连接时,get 503.在ingress中有我尝试的日志,但在webapp中没有。
我的朋友:

  1. ---
  2. # Source: yii/templates/serviceaccount.yaml
  3. apiVersion: v1
  4. kind: ServiceAccount
  5. metadata:
  6. name: myapp-yii
  7. labels:
  8. helm.sh/chart: yii-0.1.0
  9. app.kubernetes.io/name: yii
  10. app.kubernetes.io/instance: myapp
  11. app.kubernetes.io/version: "1.4.0"
  12. app.kubernetes.io/managed-by: Helm
  13. ---
  14. # Source: yii/templates/host-config.yaml
  15. kind: ConfigMap
  16. apiVersion: v1
  17. metadata:
  18. name: backend-host-config
  19. data:
  20. default.conf: |
  21. server {
  22. client_max_body_size 10m;
  23. root /var/www/web;
  24. location /health {
  25. return 200;
  26. }
  27. location / {
  28. # try to serve file directly, fallback to app.php
  29. try_files $uri /index.php$is_args$args;
  30. }
  31. location ~* ^.+\\.(css|js)$ {
  32. access_log off;
  33. log_not_found off;
  34. expires max;
  35. add_header Access-Control-Allow-Origin \"*\";
  36. }
  37. location ~* ^.+\\.(svg|svgz|eot|otf|woff|woff2|ttf|ttc|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|wav|bmp|rtf)$ {
  38. access_log off;
  39. expires max;
  40. add_header Access-Control-Allow-Origin \"*\";
  41. }
  42. location ~ ^/index\\.php(/|$) {
  43. fastcgi_pass localhost:9000;
  44. fastcgi_split_path_info ^(.+\\.php)(/.*)$;
  45. include fastcgi_params;
  46. fastcgi_send_timeout 300s;
  47. fastcgi_read_timeout 60s;
  48. fastcgi_param HTTPS on;
  49. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  50. fastcgi_param DOCUMENT_ROOT $realpath_root;
  51. http2_push_preload on;
  52. proxy_buffer_size 2048k;
  53. proxy_buffers 4 2048k;
  54. proxy_busy_buffers_size 4096k;
  55. fastcgi_buffers 16 256k;
  56. fastcgi_buffer_size 512k;
  57. internal;
  58. }
  59. location ~ \\.php$ {
  60. return 404;
  61. }
  62. }
  63. ---
  64. # Source: yii/templates/service.yaml
  65. apiVersion: v1
  66. kind: Service
  67. metadata:
  68. name: myapp-yii
  69. labels:
  70. helm.sh/chart: yii-0.1.0
  71. app.kubernetes.io/name: yii
  72. app.kubernetes.io/instance: myapp
  73. app.kubernetes.io/version: "1.4.0"
  74. app.kubernetes.io/managed-by: Helm
  75. spec:
  76. type: ClusterIP
  77. ports:
  78. - port: 80
  79. targetPort: http
  80. protocol: TCP
  81. name: http
  82. - port: 9000
  83. name: fastcgi
  84. selector:
  85. app.kubernetes.io/name: yii
  86. app.kubernetes.io/instance: myapp
  87. ---
  88. # Source: yii/templates/deployment.yaml
  89. apiVersion: apps/v1
  90. kind: Deployment
  91. metadata:
  92. name: myapp-yii
  93. labels:
  94. helm.sh/chart: yii-0.1.0
  95. app.kubernetes.io/name: yii
  96. app.kubernetes.io/instance: myapp
  97. app.kubernetes.io/version: "1.4.0"
  98. app.kubernetes.io/managed-by: Helm
  99. spec:
  100. revisionHistoryLimit: 3
  101. replicas: 1
  102. selector:
  103. matchLabels:
  104. app.kubernetes.io/name: yii
  105. app.kubernetes.io/instance: myapp
  106. template:
  107. metadata:
  108. labels:
  109. app.kubernetes.io/name: yii
  110. app.kubernetes.io/instance: myapp
  111. spec:
  112. imagePullSecrets:
  113. - name: docker-token
  114. serviceAccountName: myapp-yii
  115. securityContext:
  116. {}
  117. volumes:
  118. - name: vendor-dir
  119. emptyDir: { }
  120. - name: upload-dir
  121. emptyDir: { }
  122. - name: runtime-dir
  123. emptyDir: { }
  124. - name: assets-dir
  125. emptyDir: { }
  126. - name: host-config
  127. configMap:
  128. name: backend-host-config
  129. initContainers:
  130. - name: app-dependencies
  131. image: "[app-image]"
  132. imagePullPolicy: IfNotPresent
  133. command: ['sh', '-c', 'composer install --no-interaction --classmap-authoritative']
  134. envFrom: &envFrom
  135. - secretRef:
  136. name: backend-env
  137. volumeMounts:
  138. - mountPath: /var/www/vendor
  139. name: vendor-dir
  140. - mountPath: /var/www/web/upload
  141. name: upload-dir
  142. - mountPath: /var/www/runtime
  143. name: runtime-dir
  144. - name: app-migrations
  145. image: "[app-image]"
  146. imagePullPolicy: IfNotPresent
  147. envFrom: *envFrom
  148. volumeMounts:
  149. - mountPath: /var/www/vendor
  150. name: vendor-dir
  151. - mountPath: /var/www/web/upload
  152. name: upload-dir
  153. - mountPath: /var/www/runtime
  154. name: runtime-dir
  155. command: [ 'sh', '-c', './yii migrate --interactive=0' ]
  156. - name: app-cache-clear
  157. image: "[app-image]"
  158. imagePullPolicy: IfNotPresent
  159. envFrom: *envFrom
  160. volumeMounts:
  161. - mountPath: /var/www/vendor
  162. name: vendor-dir
  163. - mountPath: /var/www/web/upload
  164. name: upload-dir
  165. - mountPath: /var/www/runtime
  166. name: runtime-dir
  167. command: [ 'sh', '-c', './yii cache/flush-all --interactive=0' ]
  168. containers:
  169. - name: app
  170. securityContext:
  171. {}
  172. image: "[app-image]"
  173. envFrom: *envFrom
  174. imagePullPolicy: IfNotPresent
  175. volumeMounts:
  176. - mountPath: /var/www/vendor
  177. name: vendor-dir
  178. - mountPath: /var/www/web/upload
  179. name: upload-dir
  180. - mountPath: /var/www/runtime
  181. name: runtime-dir
  182. ports:
  183. - name: http
  184. containerPort: 80
  185. protocol: TCP
  186. livenessProbe:
  187. httpGet:
  188. path: /health
  189. port: http
  190. resources:
  191. {}
  192. - name: webapp
  193. image: "[webapp-image]"
  194. volumeMounts:
  195. - mountPath: /etc/nginx/conf.d
  196. name: host-config
  197. ---
  198. # Source: yii/templates/ingress.yaml
  199. apiVersion: networking.k8s.io/v1
  200. kind: Ingress
  201. metadata:
  202. name: myapp-yii
  203. labels:
  204. helm.sh/chart: yii-0.1.0
  205. app.kubernetes.io/name: yii
  206. app.kubernetes.io/instance: myapp
  207. app.kubernetes.io/version: "1.4.0"
  208. app.kubernetes.io/managed-by: Helm
  209. annotations:
  210. cert-manager.io/issuer: cert-issuer-staging
  211. certmanager.k8s.io/issuer: cert-issuer-staging
  212. ingress.kubernetes.io/ssl-redirect: "true"
  213. kubernetes.io/ingress.class: nginx
  214. kubernetes.io/tls-acme: "true"
  215. nginx.ingress.kubernetes.io/backend-protocol: http
  216. nginx.ingress.kubernetes.io/client-body-buffer-size: 1M
  217. nginx.ingress.kubernetes.io/fastcgi-index: index.php
  218. nginx.ingress.kubernetes.io/fastcgi-params-configmap: default/fastcgi-config
  219. nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
  220. nginx.ingress.kubernetes.io/http2-push-preload: "true"
  221. spec:
  222. ingressClassName: nginx
  223. tls:
  224. - hosts:
  225. - "myapp.site"
  226. secretName: myapp-tls
  227. rules:
  228. - host: "myapp.site"
  229. http:
  230. paths:
  231. - path: /
  232. pathType: ImplementationSpecific
  233. backend:
  234. service:
  235. name: myapp-yii
  236. port:
  237. name: http
  238. ---
  239. # Source: yii/templates/issuer.yaml
  240. apiVersion: cert-manager.io/v1
  241. kind: Issuer
  242. metadata:
  243. name: cert-issuer-staging
  244. spec:
  245. acme:
  246. server: https://acme-staging-v02.api.letsencrypt.org/directory
  247. email: "[email]"
  248. privateKeySecretRef:
  249. name: myapp-tls
  250. solvers:
  251. - http01:
  252. ingress:
  253. class: nginx
  254. ---
  255. # Source: yii/templates/tests/test-connection.yaml
  256. apiVersion: v1
  257. kind: Pod
  258. metadata:
  259. name: "myapp-yii-test-connection"
  260. labels:
  261. helm.sh/chart: yii-0.1.0
  262. app.kubernetes.io/name: yii
  263. app.kubernetes.io/instance: myapp
  264. app.kubernetes.io/version: "1.4.0"
  265. app.kubernetes.io/managed-by: Helm
  266. annotations:
  267. "helm.sh/hook": test
  268. spec:
  269. containers:
  270. - name: wget
  271. image: busybox
  272. command: ['wget']
  273. args: ['myapp-yii:80/health']
  274. restartPolicy: Never

字符串
当尝试通过浏览器访问时,这会出现在入口日志中:

  1. <client-ip> - - [28/Oct/2023:11:52:01 +0000] "GET / HTTP/1.1" 503 592 "-" <client-useragent> [myapp-myapp-yii-http] [] - - - - cbf11499bb04aa4c4cc2fdff838a6ff4


第一个月

  1. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  2. myapp-yii ClusterIP 10.152.183.239 <none> 80/TCP,9000/TCP 22h


kubectl get ingress -n myapp

  1. NAMESPACE NAME CLASS HOSTS ADDRESS PORTS AGE
  2. myapp myapp-yii nginx myapp.site 127.0.0.1 80, 443 13h


kubectl get deployment -n myapp

  1. NAME READY UP-TO-DATE AVAILABLE AGE
  2. myapp-yii 1/1 1 1 22h


kubectl get pod -n myapp

  1. NAME READY STATUS RESTARTS AGE
  2. myapp-yii-775597f9d8-p76rf 2/2 Running 0 13h


我不知道external-ip是<none>和/或入口地址127.0.0.1是否会影响这个问题,但我无法解决这两个问题。
编辑:为了尽量减少人为因素,我们切换到 Helm 。还尝试通过添加

  1. spec:
  2. externalIPs:
  3. - [server-ip]


这样我们就可以通过浏览器访问webapp

wyyhbhjk

wyyhbhjk1#

结果Ingress的注解毁了我们的例子,我们只留下了两个:issuer和ingress.class,现在一切都正常了

相关问题