Peter Penzov
Peter Penzov

Reputation: 1626

Remove nodeSelectorTerms param in manifest deployment

I use this manifest configuration to deploy a registry into 3 mode Kubernetes cluster:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv1
  namespace: registry-space
spec:
  capacity:
    storage: 5Gi # specify your own size
  volumeMode: Filesystem
  persistentVolumeReclaimPolicy: Retain
  local:
    path: /opt/registry # can be any path
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - kubernetes2
  accessModes:
    - ReadWriteMany # only 1 node will read/write on the path.
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv1-claim
  namespace: registry-space
spec: # should match specs added in the PersistenVolume
  accessModes:
    - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: private-repository-k8s
  namespace: registry-space
  labels:
    app: private-repository-k8s
spec:
  replicas: 1
  selector:
    matchLabels:
      app: private-repository-k8s
  template:
    metadata:
      labels:
        app: private-repository-k8s
    spec:
      volumes:
       - name: certs-vol
         hostPath:
          path: /opt/certs
          type: Directory
       - name: task-pv-storage
         persistentVolumeClaim:
           claimName: pv1-claim # specify the PVC that you've created. PVC and Deployment must be in same namespace.
      containers:
        - image: registry:2
          name: private-repository-k8s
          imagePullPolicy: IfNotPresent
          env:
          - name: REGISTRY_HTTP_TLS_CERTIFICATE
            value: "/opt/certs/registry.crt"
          - name: REGISTRY_HTTP_TLS_KEY
            value: "/opt/certs/registry.key"
          ports:
            - containerPort: 5000
          volumeMounts:
          - name: certs-vol
            mountPath: /opt/certs
          - name: task-pv-storage
            mountPath: /opt/registry

I manually created directories on every node under /opt/certs and /opt/registry.

But when I try to deploy the manifest without hardcoded nodeSelectorTerms on tha control plane I get error:

kubernetes@kubernetes1:/opt/registry$ kubectl get pods --all-namespaces
NAMESPACE        NAME                                       READY   STATUS    RESTARTS      AGE
kube-system      calico-kube-controllers-58dbc876ff-fsjd5   1/1     Running   1 (74m ago)   84m
kube-system      calico-node-5brzt                          1/1     Running   1 (73m ago)   84m
kube-system      calico-node-nph9n                          1/1     Running   1 (76m ago)   84m
kube-system      calico-node-pcd74                          1/1     Running   1 (74m ago)   84m
kube-system      calico-node-ph2ht                          1/1     Running   1 (76m ago)   84m
kube-system      coredns-565d847f94-7pswp                   1/1     Running   1 (74m ago)   105m
kube-system      coredns-565d847f94-tlrfr                   1/1     Running   1 (74m ago)   105m
kube-system      etcd-kubernetes1                           1/1     Running   2 (74m ago)   105m
kube-system      kube-apiserver-kubernetes1                 1/1     Running   2 (74m ago)   105m
kube-system      kube-controller-manager-kubernetes1        1/1     Running   2 (74m ago)   105m
kube-system      kube-proxy-4slm4                           1/1     Running   1 (76m ago)   86m
kube-system      kube-proxy-4tnx2                           1/1     Running   2 (74m ago)   105m
kube-system      kube-proxy-9dgsj                           1/1     Running   1 (73m ago)   85m
kube-system      kube-proxy-cgr44                           1/1     Running   1 (76m ago)   86m
kube-system      kube-scheduler-kubernetes1                 1/1     Running   2 (74m ago)   105m
registry-space   private-repository-k8s-6d5d954b4f-xkmj5    0/1     Pending   0             4m55s
kubernetes@kubernetes1:/opt/registry$

Do you know how I can let Kubernetes to decide where to deploy the pod?

Upvotes: 2

Views: 447

Answers (1)

sidharth vijayakumar
sidharth vijayakumar

Reputation: 1571

It seems like your node has taints hence pods are not getting scheduled. Can you try using this command to remove taints from your node ?

kubectl taint nodes  <node-name> node-role.kubernetes.io/master-

or

kubectl taint nodes --all node-role.kubernetes.io/master-

To get the node name use kubectl get nodes

User was able to get the pod scheduled after running below command:

kubectl taint nodes kubernetes1 node-role.kubernetes.io/control-plane:NoSchedule-

Now pod is failing due to crashloopbackoff this implies the pod has been scheduled.

Can you please check if this pod is getting scheduled and running properly ?

apiVersion: v1
kind: Pod
metadata:
  name: nginx1
  namespace: test
spec:
  containers:
  - name: webserver
    image: nginx:alpine
    ports:
    - containerPort: 80
    resources:
      requests:
        memory: "64Mi"
        cpu: "200m"
      limits:
        memory: "128Mi"
        cpu: "350m"

Upvotes: 2

Related Questions