kubernetes缓存清除和处理

发布于 2025-01-11 00:22:30 字数 2987 浏览 0 评论 0 原文

我使用带有 Helm 3.8.0 的 Kubernetes,并在 WSL2 上配置了 Windows docker 桌面。

有时,运行: helm install 后,并检索一个容器,在 sense 后面创建的容器是之前创建的旧容器(即使在重新启动计算机后)。

即:现在 yaml 声明的密码为:12345,数据库为:test。在我尝试使用密码:11111和数据库:my_database运行容器yaml之前。

现在,当我为当前文件夹图表执行 helm install mychart ./mychart --namespace test-chart --create-namespace 时,容器正在使用密码:11111 和数据库:my_datatbase 运行,而不是提供了新的参数。没有使用旧密码的当前 yaml 代码,所以我不明白为什么 docker 使用旧密码运行。

我做了几个操作,例如 docker system prune、重新启动 Windows Docker Desktop,但我仍然得到旧容器,看不到,即使在 Windows Docker Desktop 中,我也检查了以下选项:设置 -> 。库伯内斯 ->显示系统容器 ->显示系统容器。

经过一番调查,我意识到可能是因为 Kubernetes 有自己的容器垃圾收集处理,这就是为什么我可能会引用旧容器,即使我不是故意的。

就我而言,我正在创建一个作业模板(我没有在 _helpers.tpl 文件中放置任何引用此作业的行 - 我从未更改过该文件,并且我不知道这是否会导致问题)。

这是我的作业模板:

apiVersion: batch/v1
kind: Job
metadata:
  name: {{ include "myChart.fullname" . }}-migration
  labels:
    name: {{ include "myChart.fullname" . }}-migration
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-weight": "-300"
    "helm.sh/hook-delete-policy": before-hook-creation      
spec:
  parallelism: 1 
  completions: 1
  backoffLimit: 1
  template:
    metadata:
      labels:
        app: {{ template "myChart.name" . }}
        release: {{ .Release.Namespace }}
    spec:
      initContainers:
        - name: wait-mysql
          image: {{ .Values.mysql.image }}
          imagePullPolicy: IfNotPresent
          env:
          - name: MYSQL_ROOT_PASSWORD
            value: "12345"
          - name: MYSQL_DATABASE
            value: test
          command:
            - /bin/sh
            - -c
            - |
              service mysql start &
              until mysql -uroot -p12345 -e 'show databases'; do
                echo `date +%H:%M:%S`' - Waiting for mysql...'
                sleep 5
              done
      containers:
        - name: migration
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          command: {{- toYaml .Values.image.entrypoint | nindent 12 }}
          args: {{- toYaml .Values.image.cmd | nindent 12}}
      restartPolicy: Never

在作业中 - 首先创建一个数据库,然后它包含用代码填充的数据。

另外,注释(钩子)是必要的吗?

运行 helm install myChart ./myChart --namespace my-namespace --create-namespace 后,我意识到我正在使用非常旧的容器,我并不真正需要它。

我不明白我是否编写了元数据,如下例所示(在: 垃圾收集)确实有帮助,以及在 uid 中放入什么,无论我不知道还是没有。

 metadata:
  ...
  ownerReferences:
  - apiVersion: extensions/v1beta1
    controller: true
    blockOwnerDeletion: true
    kind: ReplicaSet
    name: my-repset
    uid: d9607e19-f88f-11e6-a518-42010a800195

有时我真的想从多个模板引用现有的 Pod(或容器)(使用同一个容器,这不是无状态的,例如数据库容器 - 一个用于 Pod 的模板,另一个用于作业) - 我该怎么做,还?

是否有任何命令(在命令行中,或一种方法)可以清除垃圾收集中的所有缓存,或者根本不使用垃圾收集? (Kubernetes的GC主要有哪些好处?)

I am using Kubernetes with Helm 3.8.0, with windows docker desktop configured on WSL2.

Sometime, after running: helm install, and retrieve a container, the container that is created behind sense, is an old container that created before (even after restarting the computer).

i.e: Now the yaml is declared with password: 12345, and database: test. before I tried to run the container yaml with password: 11111, and database: my_database.

Now when I do helm install mychart ./mychart --namespace test-chart --create-namespace for the current folder chart, the container is running with password: 11111 and database: my_datatbase, instead of the new parameters provided. There is no current yaml code with the old password, so I don't understand why the docker is run with the old one.

I did several actions, such as docker system prune, restarting Windows Docker Desktop, but still I get the old container, that cannot be seen, even in Windows Docker Desktop, I have checked the option in: Settings -> Kubernetes -> Show System Containers -> Show system containers.

After some investigations, I realized that that may be because of Kubernetes has it's own garbage collection handling of containers, and that is why I may refer to old container, even I didn't mean to.

In my case, I am creating a job template (I didn't put any line that reference this job in the _helpers.tpl file - I never changed that file, and I don't know whether that may cause a problem).

Here is my job template:

apiVersion: batch/v1
kind: Job
metadata:
  name: {{ include "myChart.fullname" . }}-migration
  labels:
    name: {{ include "myChart.fullname" . }}-migration
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-weight": "-300"
    "helm.sh/hook-delete-policy": before-hook-creation      
spec:
  parallelism: 1 
  completions: 1
  backoffLimit: 1
  template:
    metadata:
      labels:
        app: {{ template "myChart.name" . }}
        release: {{ .Release.Namespace }}
    spec:
      initContainers:
        - name: wait-mysql
          image: {{ .Values.mysql.image }}
          imagePullPolicy: IfNotPresent
          env:
          - name: MYSQL_ROOT_PASSWORD
            value: "12345"
          - name: MYSQL_DATABASE
            value: test
          command:
            - /bin/sh
            - -c
            - |
              service mysql start &
              until mysql -uroot -p12345 -e 'show databases'; do
                echo `date +%H:%M:%S`' - Waiting for mysql...'
                sleep 5
              done
      containers:
        - name: migration
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          command: {{- toYaml .Values.image.entrypoint | nindent 12 }}
          args: {{- toYaml .Values.image.cmd | nindent 12}}
      restartPolicy: Never

In the job - there is a database, which is first created, and after that it has data that is populated with code.

Also, are the annotations (hooks) are necessary?

After running helm install myChart ./myChart --namespace my-namespace --create-namespace, I realized that I am using very old container, which I don't really need.

I didn't understand if I write the meta data, as the following example (in: Garbage Collection) really help, and what to put in uid, whether I don't know it, or don't have it.

 metadata:
  ...
  ownerReferences:
  - apiVersion: extensions/v1beta1
    controller: true
    blockOwnerDeletion: true
    kind: ReplicaSet
    name: my-repset
    uid: d9607e19-f88f-11e6-a518-42010a800195

Sometimes I really want to reference existing pod (or container) from several templates (use the same container, which is not stateless, such as database container - one template for the pod and the other for the job) - How can I do that, also?

Is there any command (in command line, or a kind of method) that clear all the cached in Garbage Collection, or not use Garbage Collection at all? (What are the main benefits for the GC of Kubernetes?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文