kubeadm/kubectl/kube-apiserver turn on feature gate

yee379 picture yee379 · Feb 10, 2018 · Viewed 8.4k times · Source

i'm trying to test the local persistent volume in kubernetes v1.9.2.

from what i gather (and i may be wrong!) i cannot use kubeadm to add these feature gates:

$ sudo kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.2", GitCommit:"5fa2db2bd46ac79e5e00a4e6ed24191080aa463b", GitTreeState:"clean", BuildDate:"2018-01-18T09:42:01Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}

$ kubeadm init --help
...
      --feature-gates string                    A set of key=value pairs that describe feature gates for various features. Options are:
        CoreDNS=true|false (ALPHA - default=false)
        DynamicKubeletConfig=true|false (ALPHA - default=false)
        SelfHosting=true|false (ALPHA - default=false)
        StoreCertsInSecrets=true|false (ALPHA - default=false)
...

sooo... i do a normal kubeadm init and then proceed to hack:

/etc/systemd/system/kubelet.service.d/10-kubeadm.conf

with

Environment="KUBELET_FEATURE_GATES_ARGS=--feature-gates=PersistentLocalVolumes=true,VolumeScheduling=true,MountPropagation=true"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_AUTHZ_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CGROUP_ARGS $KUBELET_CERTIFICATE_ARGS $KUBELET_EXTRA_ARGS $KUBELET_FEATURE_GATES_ARGS

and reload/restart kubelet.

okay... let try creating the pv:

$ cat local-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: example-local-pv
  annotations:
    "volume.alpha.kubernetes.io/node-affinity": '{
      "requiredDuringSchedulingIgnoredDuringExecution": {
        "nodeSelectorTerms": [
          { "matchExpressions": [
            { "key": "kubernetes.io/hostname",
              "operator": "In",
              "values": ["dhcp-nebula-129-230"]
            }
          ]}
         ]}
        }'
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /mnt/disks/fs2

$ kubectl create -f local-pv.yaml
The PersistentVolume "example-local-pv" is invalid:
* metadata.annotations: Forbidden: Storage node affinity is disabled by 

feature-gate * spec.local: Forbidden: Local volumes are disabled by feature-gate

aha! i say... i have to change the kube-apiserver too!

so i edit /etc/kubernetes/manifests/kube-apiserver.yaml and append the following to the Command:

--feature-gates=PersistentLocalVolumes=true,VolumeScheduling=true,MountPropagation=true

and the api server dies and i'm stuck without kubectl as the kubeapi-server dies. :(

help?

Answer

Stefan P. picture Stefan P. · Feb 13, 2018

You need to set the feature gates on api, scheduler and controller in a kubeadm config:

apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
apiServerExtraArgs:
  service-node-port-range: 80-32767
  feature-gates: "PersistentLocalVolumes=true,VolumeScheduling=true,MountPropagation=true"
controllerManagerExtraArgs:
  feature-gates: "PersistentLocalVolumes=true,VolumeScheduling=true,MountPropagation=true"
schedulerExtraArgs:
  feature-gates: "PersistentLocalVolumes=true,VolumeScheduling=true,MountPropagation=true"

Storage class example:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: mysql-data
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

PVC example:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app: mariadb
  name: mysql-mariadb-0
  namespace: mysql
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  storageClassName: mysql-data
  selector:
    matchLabels:
      pod-name: mariadb-0

PV example:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-mariadb-0
  labels:
    pod-name: mariadb-0
  annotations:
    "volume.alpha.kubernetes.io/node-affinity": '{
      "requiredDuringSchedulingIgnoredDuringExecution": {
        "nodeSelectorTerms": [
          { "matchExpressions": [
              { "key": "kubernetes.io/hostname",
                "operator": "In",
                "values": ["prod-mysql-0"]
              }
          ]}
        ]}}'
spec:
  capacity:
    storage: 2Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: mysql-data
  local:
    path: /mnt/local-storage/mysql-data-0