【问题标题】:kubernetes on microk8s yaml file not workingmicrok8s yaml文件上的kubernetes无法正常工作
【发布时间】:2022-01-20 18:16:21
【问题描述】:

昨天在私人笔记本上安装了kubernetes microk8s,学习kubernetes, 但即使在第一个带有 PersistentVolume 的简单文件上,我也会遇到很多验证错误,

我已经从以下来源在 Ubuntu 上安装了 microk8s: https://microk8s.io/?_ga=2.70856272.1723042697.1642604373-620897147.1642604373v

问题是我第一次想创建 pv:

apiVersion: v1
kind: PersistentVolume
metadata:
name: redis-pv
spec:
storageClassName: ""
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"

我得到以下错误:

kubectl apply -f pv-data.yml -n testing

error: error validating "pv-data.yml": error validating data: [ValidationError(PersistentVolume): unknown field "accessModes" in io.k8s.api.core.v1.PersistentVolume, ValidationError(PersistentVolume): unknown field "name" in io.k8s.api.core.v1.PersistentVolume, ValidationError(PersistentVolume): unknown field "path" in io.k8s.api.core.v1.PersistentVolume, ValidationError(PersistentVolume): unknown field "storage" in io.k8s.api.core.v1.PersistentVolume, ValidationError(PersistentVolume): unknown field "storageClassName" in io.k8s.api.core.v1.PersistentVolume]; if you choose to ignore these errors, turn validation off with --validate=false

有人可以帮我吗?也许我没有正确安装 microk8s ?因为这是一个非常简单的 yaml 文件。

我也想附上 microk8s 的状态:

microk8s status

microk8s is running
high-availability: no
  datastore master nodes: 127.0.0.1:19001
  datastore standby nodes: none
addons:
  enabled:
    dashboard            # The Kubernetes dashboard
    dns                  # CoreDNS
    ha-cluster           # Configure high availability on the current node
    ingress              # Ingress controller for external access
    metrics-server       # K8s Metrics Server for API access to service metrics
  disabled:
    ambassador           # Ambassador API Gateway and Ingress
    cilium               # SDN, fast with full network policy
    dashboard-ingress    # Ingress definition for Kubernetes dashboard
    fluentd              # Elasticsearch-Fluentd-Kibana logging and monitoring
    gpu                  # Automatic enablement of Nvidia CUDA
    helm                 # Helm 2 - the package manager for Kubernetes
    helm3                # Helm 3 - Kubernetes package manager
    host-access          # Allow Pods connecting to Host services smoothly
    inaccel              # Simplifying FPGA management in Kubernetes
    istio                # Core Istio service mesh services
    jaeger               # Kubernetes Jaeger operator with its simple config
    kata                 # Kata Containers is a secure runtime with lightweight VMS
    keda                 # Kubernetes-based Event Driven Autoscaling
    knative              # The Knative framework on Kubernetes.
    kubeflow             # Kubeflow for easy ML deployments
    linkerd              # Linkerd is a service mesh for Kubernetes and other frameworks
    metallb              # Loadbalancer for your Kubernetes cluster
    multus               # Multus CNI enables attaching multiple network interfaces to pods
    openebs              # OpenEBS is the open-source storage solution for Kubernetes
    openfaas             # OpenFaaS serverless framework
    portainer            # Portainer UI for your Kubernetes cluster
    prometheus           # Prometheus operator for monitoring and logging
    rbac                 # Role-Based Access Control for authorisation
    registry             # Private image registry exposed on localhost:32000
    storage              # Storage class; allocates storage from host directory
    traefik              # traefik Ingress controller for external access

【问题讨论】:

  • yaml 对缩进非常严格,原因是它允许嵌入其他类型的内容,只能使用缩进来知道事情的开始和结束。
  • 要非常小心,因为如果你弄错了缩进,你会得到很多不同的错误和事情不起作用!享受吧。

标签: kubernetes microk8s


【解决方案1】:

yaml缩进相关的问题,可以参考网上有效的例子

https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/

或者只是尝试根据你的直觉修复它,大多数时候你可以完成它

apiVersion: v1
kind: PersistentVolume
metadata:
 name: redis-pv
spec:
 storageClassName: ""
 capacity:
   storage: 1Gi
 accessModes:
 - ReadWriteOnce
 hostPath:
   path: "/mnt/data"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    相关资源
    最近更新 更多