资源缺少 kubectl.kubernetes.io/last-applied-configuration

问题描述 投票:0回答:1

当我应用带有部署和服务的文件时,我收到了这两个警告。我已经验证过,但我使用相同的命名空间:test,并且 ConfigMap 名为:nginx-config 有什么问题吗? 但我的 Pod 工作正常。

1

Warning: resource deployments/nginx is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
deployment.apps/nginx configured

2

Warning: resource services/nginx is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.

我的代码:

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
  namespace: test
data:
  nginx.conf: '
events {
}
http {
   server {
       listen 80;
       location / {
           return 200 "Hello world 2024!";
       }
   }
}
'
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: test
spec:
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
      #- image: registry.gitlab.peruprop.com/root/freetest:1.0
        name: nginx
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
          - name: config-vol
            mountPath: /etc/nginx/
      volumes:
        - name: config-vol
          configMap:
            name: nginx-config
            items:
              - key: nginx.conf
                path: nginx.conf
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx
  namespace: test
spec:
  ports:
  - name: 80-80
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: ClusterIP
kubernetes kubectl
1个回答
0
投票

您可以安全地忽略这些警告。它们只是意味着您使用

kubectl apply
而不是
kubectl create
在 Kubernetes 中创建对象,这完全没问题。

通常

kubectl apply
用于更新对象,但也可以用于创建对象。

您可以在此处阅读有关

kubectl.kubernetes.io/last-applied-configuration
注释的更多信息:https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/#how-to-create-objects

© www.soinside.com 2019 - 2024. All rights reserved.