kubernetes on microk8s yaml file not working

1/20/2022

Yesterday, I installed kubernetes microk8s on my private laptop to learn about kubernetes, But even on first simple file with PersistentVolume I'm getting a lot of validation errors,

I have installed microk8s on Ubuntu from below source: https://microk8s.io/?_ga=2.70856272.1723042697.1642604373-620897147.1642604373v

The issue is when firstly I wanted to create pv:

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

and I'm gettting below errors:

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

Can someone help me with that ? Maybe I have microk8s not properly installed ? Because this is very simple yaml file.

also I would like to attach status of 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
-- dominbdg
kubernetes
microk8s

1 Answer

1/20/2022

Issue related to yaml indentation , you can use valid online examples like

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

or just try fix it on your intuition , most of time you can make it done

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