I have deployed a Drupal Instance but i see that the instance Endpoint are not visible although the containers deployed successfully

7/12/2020

I have deployed a Drupal Instance but i see that the instance Endpoint are not visible although the containers deployed successfully.

Container logs don't point to any direction

apiVersion: apps/v1
kind: Deployment
metadata:
  name: drupal-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: drupal
      type: frontend
  template:
    metadata:
      labels:
        app: drupal
    spec:
      containers:
      - name: drupal
        image: drupal
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
 
**********************
apiVersion: v1
kind: Service
metadata:
  name: drupal-service
 
spec: 
  type: NodePort
  ports: 
    - targetPort: 80
      port: 80
      nodePort: 30010
  selector: 
      app: drupal
      type: frontend
************************`
root@ip-172-31-32-54:~# microk8s.kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
drupal-deployment-6fdd7975f-l4j2z   1/1     Running   0          9h
drupal-deployment-6fdd7975f-p7sfz   1/1     Running   0          9h
root@ip-172-31-32-54:~# microk8s.kubectl get services
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
drupal-service   NodePort    10.152.183.6   <none>        80:30010/TCP   9h
kubernetes       ClusterIP   10.152.183.1   <none>        443/TCP        34h
***********************
root@ip-172-31-32-54:~# microk8s.kubectl describe service drupal-service
Name:                     drupal-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=drupal,type=frontend
Type:                     NodePort
IP:                       10.152.183.6
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30010/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

Any directions is really helpful.

NOTE: This works perfectly when running a container using the command

docker run --name some-drupal -p 8080:80 -d drupal

Thank you, Anish

-- anish anil
drupal
drupal-8
k3s
kubernetes
microk8s

1 Answer

7/13/2020

Your service selector has two values:

Selector:                 app=drupal,type=frontend

but your pod has only one of these:

spec:
  template:
    metadata:
      labels:
        app: drupal

Just make sure that all labels required by the service actually exist on the pod.

Like following:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: drupal-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: drupal
      type: frontend
  template:
    metadata:
      labels:
        app: drupal
        type: frontend   #     <--------- look here
    spec:
      containers:
      - name: drupal
        image: drupal
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
-- Matt
Source: StackOverflow