1

I'm following below to launch a multi-container app (db and web-app). Following is based on this.

--- BLOW STEPS ARE COPIED FROM ANSWER PROVIDED BY THIS USER docker mysql in kuberneted ERROR 2005 (HY000): Unknown MySQL server host '' (-3) ---

First, use your favorite editor to start a eramba-cm.yaml file:

    apiVersion: v1
kind: ConfigMap
metadata:
  name: eramba
  namespace: eramba-1
data:
  c2.8.1.sql: |
    CREATE DATABASE IF NOT EXISTS erambadb;
    USE erambadb;
    ## IMPORTANT: MUST BE INDENT 2 SPACES AFTER c2.8.1.sql ##
    <copy & paste content from here: https://raw.githubusercontent.com/markz0r/eramba-community-docker/master/sql/c2.8.1.sql>

kubectl create -f eramba-cm.yaml

Create the storage for MariaDB:

    cat << EOF > eramba-storage.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: eramba-storage
spec:
  storageClassName: eramba-storage
  capacity:
    storage: 5Gi
  accessModes: 
  - ReadWriteOnce
  hostPath:
    path: /home/osboxes/eramba/erambadb
    type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: eramba-storage
  namespace: eramba-1
spec:
  storageClassName: eramba-storage
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
...
EOF

kubectl create -f eramba-storage.yaml

Install bitnami/mariadb using Helm

helm repo add bitnami https://charts.bitnami.com/bitnami
helm upgrade -i eramba bitnami/mariadb --set auth.rootPassword=eramba,auth.database=erambadb,initdbScriptsConfigMap=eramba,volumePermissions.enabled=true,primary.persistence.existingClaim=eramba-storage --namespace eramba-1 --set mariadb.volumePermissions.enabled=true

Run eramba web application:

    apiVersion: apps/v1
kind: Deployment
metadata:
  name: eramba-web
  namespace: eramba-1
  labels:
    app.kubernetes.io/name: eramba-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: eramba-web
  template:
    metadata:
      labels:
        app: eramba-web
    spec:
      containers:
      - name: eramba-web
        image: markz0r/eramba-app:c281
        imagePullPolicy: IfNotPresent
        env:
        - name: MYSQL_HOSTNAME
          value: eramba-mariadb
        - name: MYSQL_DATABASE
          value: erambadb
        - name: MYSQL_USER
          value: root
        - name: MYSQL_PASSWORD
          value: eramba
        - name: DATABASE_PREFIX
          value: ""
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: eramba-web
  namespace: eramba-1
  labels:
    app.kubernetes.io/name: eramba-web
spec:
  ports:
  - name: http
    nodePort: 30045
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app.kubernetes.io/name: eramba-web
  type: NodePort
...

Now browse eramba-web via port-forward or http://<node ip>:30045.

The kubectl get cm,pvc,pv,svc,pods output is:

root@osboxes:~# kubectl get cm,pvc,pv,svc,pods -o wide -n eramba-1
NAME                         DATA   AGE
configmap/eramba             1      134m
configmap/eramba-mariadb     1      131m
configmap/kube-root-ca.crt   1      29h

NAME                                   STATUS   VOLUME           CAPACITY   ACCESS MODES   STORAGECLASS     AGE    VOLUMEMODE
persistentvolumeclaim/eramba-storage   Bound    eramba-storage   5Gi        RWO            eramba-storage   133m   Filesystem

NAME                              CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                     STORAGECLASS     REASON   AGE    VOLUMEMODE
persistentvolume/eramba-storage   5Gi        RWO            Retain           Bound    eramba-1/eramba-storage   eramba-storage            133m   Filesystem

NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE    SELECTOR
service/eramba-mariadb   ClusterIP   10.104.161.85   <none>        3306/TCP         131m   app.kubernetes.io/component=primary,app.kubernetes.io/instance=eramba,app.kubernetes.io/name=mariadb
service/eramba-web       NodePort    10.100.185.75   <none>        8080:30045/TCP   129m   app.kubernetes.io/name=eramba-web

NAME                              READY   STATUS    RESTARTS   AGE    IP          NODE      NOMINATED NODE   READINESS GATES
pod/eramba-mariadb-0              1/1     Running   0          131m   10.20.0.6   osboxes   <none>           <none>
pod/eramba-web-6cc9c687d8-k6r9j   1/1     Running   0          129m   10.20.0.7   osboxes   <none>           <none>

When I tried to access 10.100.185.75:30045, the browser is says not reachable.

root@osboxes:/home/osboxes/eramba# kubectl describe service/eramba-web -n eramba-1
Name:                     eramba-web
Namespace:                eramba-1
Labels:                   app.kubernetes.io/name=eramba-web
Annotations:              <none>
Selector:                 app.kubernetes.io/name=eramba-web
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.100.185.75
IPs:                      10.100.185.75
Port:                     http  8080/TCP
TargetPort:               8080/TCP
NodePort:                 http  30045/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:

the logs for the web-app pod:

root@osboxes:~# kubectl logs eramba-web-6cc9c687d8-k6r9j -n eramba-1
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.20.0.7. Set the 'ServerName' directive globally to suppress this message
root@osboxes:~# 

I've noticed the lack of endpoint for the Eramba-web service. When I changed the selector app to eramba-web, the endpoint has an IP, but the browser still cant reach the app.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Bryan
  • 67
  • 7
  • 1
    A `NodePort` service is exposed on the ip addresses of cluster nodes. The `10.100.x.y` address is an internal address you won't be able to access. – larsks Jan 09 '22 at 00:55
  • ahhh I see. How would I fix this? – Bryan Jan 09 '22 at 01:10
  • By using the ip address of one of the kubernetes nodes instead of that 10.100 address (or exposing the service using an [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) instead). – larsks Jan 09 '22 at 01:19
  • lol I'm dumb. It's the IP returned by kubectl get nodes -o yaml – Bryan Jan 09 '22 at 01:44
  • Oh sorry I didn't know I couldn't do that :( - your answer was awesome! I planned to edit it and promote as answer. Sorry I will credit you in this post. – Bryan Jan 09 '22 at 02:15
  • the reason why I didn't link you was because I modified the namespace and pod deployment btw. I figured it would be easier for the readers to read the new yaml instead of saying "I added namespace" in case it was my yaml files acting up – Bryan Jan 09 '22 at 02:20

1 Answers1

0

This is a community wiki answer posted for better visibility. Feel free to expand it.

The requester uses the NodePort type for the eramba-web service. To access the application, it necessary to use the IP addresses of the nodes in the cluster, instead of using the internal IP address 10.100.x.y.

From Kubernetes documentation:

NodePort: Exposes the Service on each Node's IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You'll be able to contact the NodePort Service, from outside the cluster, by requesting <NodeIP>:<NodePort>.

Andrew Skorkin
  • 1,147
  • 3
  • 11