> For the complete documentation index, see [llms.txt](https://fufu.gitbook.io/kk8s/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fufu.gitbook.io/kk8s/task-memory/23.ingress-ssl-secret.md).

# 網站提供 https 安全連線服務 - 憑證與Ingress整合

`Ingress`要整合`Cert-Manager`的憑證，會因為各方實作方式不同，`ingress`設定會略有不同。\
下面以 **nginx ingress** 整合憑證前後之範例：

### Ingress http resource 範例

```yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: simple-fanout-example
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /foo
        backend:
          serviceName: service1
          servicePort: 4200
      - path: /bar
        backend:
          serviceName: service2
          servicePort: 8080
```

### Ingress HTTPS resource 範例

#### 憑證

下面，透過`Cert-manager`申請與取得的憑證資訊，存放於 **K8s secret** 裏頭。

```yaml
apiVersion: v1
kind: Secret
metadata:
  name: testsecret-tls
  namespace: default
data:
  tls.crt: base64 encoded cert
  tls.key: base64 encoded key
type: kubernetes.io/tls
```

#### ingress 使用憑證

```yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: tls-example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  tls:
  - hosts:
    - sslexample.foo.com
    secretName: testsecret-tls
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /foo
        backend:
          serviceName: service1
          servicePort: 4200
      - path: /bar
        backend:
          serviceName: service2
          servicePort: 8080
```

此處要注意的重點就是：`spec.tls.hosts` \ `secretName`\
這裡指定了使用`testsecret-tls`此張憑證，於此網站入口`ingress`使用，如此網站拜訪者即可使用具備 **SSL**安全通道的**HTTPS** 入口網站服務。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://fufu.gitbook.io/kk8s/task-memory/23.ingress-ssl-secret.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
