> For the complete documentation index, see [llms.txt](https://doc.spotmaxtech.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.spotmaxtech.com/she-qu-huo-dong/techdoc/2023.6-ji-yi-ci-eks-1.221.25-sheng-ji.md).

# 2023.5 记一次EKS 1.22->1.26 升级

## Summary

环境：EKS 1.22，5个节点，有statefulset、deployment服务

采用原地in-place方式升级，记录下来发生的事项

<table><thead><tr><th width="151.5">版本</th><th>注意事项</th></tr></thead><tbody><tr><td>1.22-1.23</td><td><ul><li>EBS CSI 插件和IAM Role升级</li><li>Node rolling update要求事先解除节点IP依赖</li><li>kube-proxy 升级</li></ul></td></tr><tr><td>1.23-1.24</td><td>无，顺利完成</td></tr><tr><td>1.24-1.25</td><td>无，顺利完成</td></tr><tr><td>1.25-1.26</td><td>无，顺利完成</td></tr></tbody></table>

## 过程记录点

EKS升级时会提示，注意阅读

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FIhdLr82IRxdNsF6FYX0V%2Fimage.png?alt=media&amp;token=87ba0b0b-3918-49f0-a582-42eb4b04e2a4" alt=""><figcaption></figcaption></figure>

根据1.22升级到1.23时，需要事先安装EBS CSI Driver

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FAnMPnVjMBr4MFgb5nwQm%2Fimage.png?alt=media&amp;token=e43c2749-4cbf-4f54-9d88-4d9cfbd66461" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FAfquA7rR9sArqpvKmPbX%2Fimage.png?alt=media&amp;token=3bded010-057a-4b82-997d-811a81c3ce63" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FM7VYn2jYBidHBxTmNxAk%2Fimage.png?alt=media&amp;token=eaad75fc-8ef1-4a0c-8e7f-bbf68ae865cd" alt="" width="563"><figcaption></figcaption></figure>

EBSCSIDriver需要权限，所以确认一下IAM Role是否有这个权限policy

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FK290ZrnBSjzhvXfqbhiR%2Fimage.png?alt=media&amp;token=2fb76878-cef4-4aff-82e5-c50376d25d30" alt=""><figcaption></figcaption></figure>

确认完毕即可升级到1.23了，不过要确认当前的Node和Master是否为一致版本1.22，否则也不能升级到1.23

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FSLae5I1MU4Mzjxm6lVCR%2Fimage.png?alt=media&amp;token=3f44b51b-23eb-4ff9-8925-eb4186cd9c19" alt="" width="375"><figcaption></figcaption></figure>

按照要求升级Node Group即可

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FaufS3xCTgx9AUuWY3iom%2Fimage.png?alt=media&amp;token=b6f802e0-ec6b-42e3-b09a-5423fa841753" alt=""><figcaption></figcaption></figure>

因为EKS每次升级都需要保持Node和Master的一致，而Node升级会发生IP变更，一定要避免在配置文件中使用固定IP，例如如下为redis创建一个service服务

```yaml
apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  selector:
    app: redis
  ports:
  - port: 6480
    targetPort: 6480
```

容易忽略的地方是DNS策略，尤其我们使用了hostnetwork时，要参考ClusterFirstWithHostNet的使用，排查DNS问题时注意这个地方

> Kubernetes DNS Policy 是指 Kubernetes 集群中用于控制容器访问 DNS 的策略。以下是 Kubernetes DNS 策略的几种类型：
>
> 1. `ClusterFirst`：这是默认选项，当 Pod 中的容器需要进行 DNS 查询时，会优先使用 Kubernetes 集群中的 DNS 服务。如果查询失败，才会尝试使用其他配置的 DNS 服务器。
> 2. `ClusterFirstWithHostNet`：这个选项与 `ClusterFirst` 类似，不同之处在于它适用于使用 HostNetwork 模式的 Pod，即容器共享主机网络栈的 Pod。因为容器和主机网络栈共享了相同的网络命名空间，所以容器可以直接访问主机上的 DNS 服务。
> 3. `Default`：这个选项直接使用 Pod 所在节点上的 DNS 服务器解析 DNS 查询请求，而不是使用 Kubernetes 集群中的 DNS 服务。
> 4. `None`：这个选项表示禁止 DNS 查询功能。这在某些高安全性场景下很有用，但通常情况下不建议使用。
>
> 除了上述四种类型，还有两个特殊的类型：
>
> 5. `External`：这个选项定义了自定义 DNS 配置。Pod 访问 DNS 将直接使用该配置。
> 6. `Cache`： 这个选项仅适用于 CoreDNS，它将DNS查询结果缓存在CoreDNS中，下次DNS查询时直接返回缓存结果，从而提高查询效率。

关于kube-proxy虽然EKS没有强制要求跟随每个版本一起升级，但是为了线上稳定性，最好还是一起升级。至于会发生什么问题，这个是未知的，有可能发生master与node通信协议的不一致导致错误。

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FjQ8S0c6T95U5giv2oqra%2Fimage.png?alt=media&amp;token=f04a9509-8d53-46a2-bc8d-9e50ef38ecaf" alt="" width="563"><figcaption></figcaption></figure>

EKS升级proxy注意调整configmap出现冲突时的模式，例如设置为override

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FyG9cHMdA2yRdJAWIGF1j%2Fimage.png?alt=media&amp;token=4b6a8eef-f7f4-48c7-8603-0c005ede3703" alt="" width="563"><figcaption></figcaption></figure>

1.23 1.24没有额外特别注意的，1.25时有一个提示PSP，根据各自情况判断，我们这里没有使用PSP

<figure><img src="https://2782895870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZNgugMYXt9ujbhVZqNea%2Fuploads%2FdUuir0f92qgmowuDRH0m%2Fimage.png?alt=media&amp;token=c2a2f4cb-16d8-45e9-812f-299e4f2afd05" alt=""><figcaption></figcaption></figure>

至此，我们安全的完成了1.22至1.26的升级，检查没有发生问题。最后，总结下实践经验，当然需要根据各自情况做抉择

> AWS EKS 升级的最佳实践：
>
> 1. **备份数据**：在开始升级过程之前，建议先备份 Kubernetes 资源和数据。这有助于在升级过程中出现任何意外情况时进行恢复。
> 2. **了解升级流程**：AWS EKS 提供两种类型的升级——控制平面升级和节点组升级。控制平面升级涉及升级 EKS 控制平面的 Kubernetes 版本，该平面管理集群的 API 交互和工作负载管理。节点组升级涉及升级集群中节点的 Kubernetes 版本。
> 3. **检查兼容性**：确保您使用的所有附加组件和工具与新的 EKS 版本兼容。您可以在官方 AWS EKS 文档页面上检查附加组件和工具的兼容性。
> 4. **查看发布说明**：查看新的 EKS 版本的发布说明，了解更改和新功能。这将帮助您为应用程序或基础架构所需的任何更改做好准备。
> 5. **在非生产环境中测试升级**：在升级生产环境之前，最好在非生产环境中测试升级。这将确保升级过程顺利进行，不会影响您的生产环境。
> 6. **按照推荐升级路径进行操作**：AWS EKS 为每个版本提供了推荐的升级路径。按照推荐的升级路径进行操作，以避免任何兼容性问题。
> 7. **监控升级进度**：在升级过程中，密切监视进展。AWS EKS 提供各种工具，如 CloudWatch 日志、Amazon SNS 和 Amazon EventBridge 来监视升级进度。
> 8. **验证升级后的集群**：完成升级后，请运行一些测试来验证升级后的集群是否正常运行。
> 9. **清理**：验证升级后的集群后，请清理任何未使用的资源，以最小化成本。
>
> 通过遵循这些最佳实践，您可以顺利地升级 AWS EKS 版本，而不会出现任何问题。


---

# 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://doc.spotmaxtech.com/she-qu-huo-dong/techdoc/2023.6-ji-yi-ci-eks-1.221.25-sheng-ji.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.
