Saturday, April 10, 2021

Gradle test project

HOWTO

GitHub repo

Initialize project 

[dave@dave git]$ cd gradle-demo/
[dave@dave gradle-demo]$ gradle init

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 2

Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Scala
  6: Swift
Enter selection (default: Java) [1..6] 3

Split functionality across multiple subprojects?:
  1: no - only one application project
  2: yes - application and library projects
Enter selection (default: no - only one application project) [1..2] 2

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Project name (default: gradle-demo): 
Source package (default: gradle.demo): 

> Task :init
Get more help with your project: https://docs.gradle.org/7.0/samples/sample_building_java_applications_multi_project.html

BUILD SUCCESSFUL in 41s
2 actionable tasks: 2 executed

Project structure
[dave@dave gradle-demo]$ find
.
./gradle
./gradle/wrapper
./gradle/wrapper/gradle-wrapper.jar
./gradle/wrapper/gradle-wrapper.properties
./settings.gradle
./.gradle
./.gradle/configuration-cache
./.gradle/configuration-cache/gc.properties
./.gradle/7.0
./.gradle/7.0/fileChanges
./.gradle/7.0/fileChanges/last-build.bin
./.gradle/7.0/gc.properties
./.gradle/7.0/dependencies-accessors
./.gradle/7.0/dependencies-accessors/gc.properties
./.gradle/7.0/dependencies-accessors/dependencies-accessors.lock
./.gradle/7.0/vcsMetadata-1
./.gradle/7.0/executionHistory
./.gradle/7.0/executionHistory/executionHistory.lock
./.gradle/7.0/executionHistory/executionHistory.bin
./.gradle/7.0/fileHashes
./.gradle/7.0/fileHashes/fileHashes.lock
./.gradle/7.0/fileHashes/fileHashes.bin
./.gradle/buildOutputCleanup
./.gradle/buildOutputCleanup/buildOutputCleanup.lock
./.gradle/buildOutputCleanup/outputFiles.bin
./.gradle/buildOutputCleanup/cache.properties
./.gradle/checksums
./.gradle/checksums/checksums.lock
./.gradle/vcs-1
./.gradle/vcs-1/gc.properties
./gradlew.bat
./buildSrc
./buildSrc/build.gradle
./buildSrc/src
./buildSrc/src/main
./buildSrc/src/main/groovy
./buildSrc/src/main/groovy/gradle.demo.java-common-conventions.gradle
./buildSrc/src/main/groovy/gradle.demo.java-library-conventions.gradle
./buildSrc/src/main/groovy/gradle.demo.java-application-conventions.gradle

./app
./app/build.gradle
./app/src
./app/src/main
./app/src/main/java
./app/src/main/java/gradle
./app/src/main/java/gradle/demo
./app/src/main/java/gradle/demo/app
./app/src/main/java/gradle/demo/app/MessageUtils.java
./app/src/main/java/gradle/demo/app/App.java
./app/src/main/resources
./app/src/test
./app/src/test/java
./app/src/test/java/gradle
./app/src/test/java/gradle/demo
./app/src/test/java/gradle/demo/app
./app/src/test/java/gradle/demo/app/MessageUtilsTest.java
./app/src/test/resources
./.gitattributes
./utilities
./utilities/build.gradle
./utilities/src
./utilities/src/main
./utilities/src/main/java
./utilities/src/main/java/gradle
./utilities/src/main/java/gradle/demo
./utilities/src/main/java/gradle/demo/utilities
./utilities/src/main/java/gradle/demo/utilities/SplitUtils.java
./utilities/src/main/java/gradle/demo/utilities/StringUtils.java
./utilities/src/main/java/gradle/demo/utilities/JoinUtils.java
./utilities/src/main/resources
./utilities/src/test
./utilities/src/test/resources
./gradlew
./README.md
./list
./list/build.gradle
./list/src
./list/src/main
./list/src/main/java
./list/src/main/java/gradle
./list/src/main/java/gradle/demo
./list/src/main/java/gradle/demo/list
./list/src/main/java/gradle/demo/list/LinkedList.java
./list/src/main/resources
./list/src/test
./list/src/test/java
./list/src/test/java/gradle
./list/src/test/java/gradle/demo
./list/src/test/java/gradle/demo/list
./list/src/test/java/gradle/demo/list/LinkedListTest.java
./list/src/test/resources
./.gitignore

Main
[dave@dave gradle-demo]$ more settings.gradle 
/*
 * This file was generated by the Gradle 'init' task.
 *
 * The settings file is used to specify which projects to include in your build.
 *
 * Detailed information about configuring a multi-project build in Gradle can be found
 * in the user manual at https://docs.gradle.org/7.0/userguide/multi_project_builds.html
 */

rootProject.name = 'gradle-demo'
include('app', 'list', 'utilities')

Run tests
[dave@dave gradle-demo]$ ./gradlew check
Downloading https://services.gradle.org/distributions/gradle-7.0-bin.zip
..........10%...........20%...........30%..........40%...........50%...........60%...........70%..........80%...........90%...........100%

BUILD SUCCESSFUL in 32s
9 actionable tasks: 9 executed

Run application
[dave@dave gradle-demo]$ ./gradlew run

> Task :app:run
Hello World!

BUILD SUCCESSFUL in 989ms
6 actionable tasks: 1 executed, 5 up-to-date

Build
[dave@dave gradle-demo]$ ./gradlew build

BUILD SUCCESSFUL in 970ms
13 actionable tasks: 4 executed, 9 up-to-date

Publish
[dave@dave gradle-demo]$ ./gradlew build --scan

BUILD SUCCESSFUL in 4s
13 actionable tasks: 13 up-to-date

Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https://gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes

Gradle Terms of Service accepted.

Publishing build scan...
https://gradle.com/s/v7pfqpbcuendg

Monday, April 5, 2021

LDAP search

HOWTO

 

LDAP test server

LDAP Server Information (read-only access):

Server: ldap.forumsys.com  
Port: 389

Bind DN: cn=read-only-admin,dc=example,dc=com
Bind Password: password

All user passwords are password.

 

 Search using test  server

[dave@dave git]$ ldapsearch -W -h ldap.forumsys.com -D "cn=read-only-admin,dc=example,dc=com" -b "dc=example,dc=com"  "uid=Newton" 
Enter LDAP Password: 
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=com> with scope subtree
# filter: uid=Newton
# requesting: ALL
#

# newton, example.com
dn: uid=newton,dc=example,dc=com
sn: Newton
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
uid: newton
mail: newton@ldap.forumsys.com
cn: Isaac Newton

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

Select attributes
[dave@dave git]$ ldapsearch -W -h ldap.forumsys.com -D "cn=read-only-admin,dc=example,dc=com" -b "dc=example,dc=com"  "uid=Newton" mail
Enter LDAP Password: 
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=com> with scope subtree
# filter: uid=Newton
# requesting: mail 
#

# newton, example.com
dn: uid=newton,dc=example,dc=com
mail: newton@ldap.forumsys.com

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

Search using Java https://github.com/dveselka/java-tutorial/blob/master/src/main/java/ldap/TestLDAP.java
package ldap;

import java.util.ArrayList;
import java.util.Properties;


import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute;
import javax.naming.Context;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;

public class TestLDAP {
    private static final String CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";

    private InitialDirContext ctx;
    private String basedn;
    private SearchControls ctrls;

    private TestLDAP(String url, String user, String password, String b) throws NamingException {
        ctx = TestLDAP.doConnect(url, user, password);
        basedn = b.length() > 0 ? "," + b : b;
        ctrls = new SearchControls();
    }

    public ArrayList<Attributes> search(String base, String filter) throws NamingException {
        NamingEnumeration<SearchResult> ne = ctx.search(base + basedn, filter, ctrls);
        ArrayList<Attributes> arr = new ArrayList<>();
        while (ne.hasMore()) {
            arr.add(ne.next().getAttributes());
        }
        return arr;
    }

    public Attributes get(String base) throws NamingException {
        return ctx.getAttributes(base + basedn);
    }

    private static InitialDirContext doConnect(String url, String user, String password) throws NamingException {
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
        props.put(Context.PROVIDER_URL, url);
        props.put(Context.SECURITY_PRINCIPAL, user);
        props.put(Context.SECURITY_CREDENTIALS, password);

        return new InitialDirContext(props);
    }

    public static TestLDAP connect(String url, String user, String pass, String basedn) throws NamingException {
        return new TestLDAP(url, user, pass, basedn);
    }

    public static boolean testConnection(String url, String user, String password) {
        try {
            return TestLDAP.doConnect(url, user, password) != null;
        } catch (Exception e) {
            return false;
        }
    }

    public static void main(String[] args) {
        try {
            TestLDAP testLDAP = new TestLDAP("ldap://ldap.forumsys.com", "cn=read-only-admin,dc=example,dc=com",
                    "password", "dc=example,dc=com");
            Attributes attributes = testLDAP.get("uid=Newton");

            NamingEnumeration<? extends Attribute> allAttributes = attributes.getAll();
            while (allAttributes.hasMore()) {
                Attribute attribute = allAttributes.next();
                System.out.println(attribute.getID() + "=" + attribute.get().toString());
            }

        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}
Run code in Eclipse

Saturday, March 20, 2021

k8s minikube addons

 HOWTO

 

Get addons list
[dave@dave ~]$ minikube addons list
|-----------------------------|----------|--------------|
|         ADDON NAME          | PROFILE  |    STATUS    |
|-----------------------------|----------|--------------|
| ambassador                  | minikube | disabled     |
| auto-pause                  | minikube | disabled     |
| csi-hostpath-driver         | minikube | disabled     |
| dashboard                   | minikube | enabled ✅   |
| default-storageclass        | minikube | enabled ✅   |
| efk                         | minikube | disabled     |
| freshpod                    | minikube | disabled     |
| gcp-auth                    | minikube | disabled     |
| gvisor                      | minikube | disabled     |
| helm-tiller                 | minikube | disabled     |
| ingress                     | minikube | enabled ✅   |
| ingress-dns                 | minikube | disabled     |
| istio                       | minikube | disabled     |
| istio-provisioner           | minikube | disabled     |
| kubevirt                    | minikube | disabled     |
| logviewer                   | minikube | disabled     |
| metallb                     | minikube | disabled     |
| metrics-server              | minikube | disabled     |
| nvidia-driver-installer     | minikube | disabled     |
| nvidia-gpu-device-plugin    | minikube | disabled     |
| olm                         | minikube | disabled     |
| pod-security-policy         | minikube | disabled     |
| registry                    | minikube | disabled     |
| registry-aliases            | minikube | disabled     |
| registry-creds              | minikube | disabled     |
| storage-provisioner         | minikube | enabled ✅   |
| storage-provisioner-gluster | minikube | disabled     |
| volumesnapshots             | minikube | disabled     |
|-----------------------------|----------|--------------|

enable metrics
[dave@dave ~]$ minikube addons enable metrics-server
    ▪ Using image k8s.gcr.io/metrics-server-amd64:v0.2.1
🌟  The 'metrics-server' addon is enabled


get metrics
[dave@dave ~]$ kubectl get pod,svc -n kube-system
NAME                                            READY   STATUS      RESTARTS   AGE
pod/coredns-74ff55c5b-vkbhb                     1/1     Running     3          6d18h
pod/etcd-minikube                               1/1     Running     2          5d21h
pod/ingress-nginx-admission-create-mqrgx        0/1     Completed   0          5d12h
pod/ingress-nginx-admission-patch-5hsm2         0/1     Completed   0          5d12h
pod/ingress-nginx-controller-65cf89dc4f-64d9n   1/1     Running     4          5d12h
pod/kube-apiserver-minikube                     1/1     Running     2          5d21h
pod/kube-controller-manager-minikube            1/1     Running     3          6d18h
pod/kube-proxy-jfktf                            1/1     Running     3          6d18h
pod/kube-scheduler-minikube                     1/1     Running     3          6d18h
pod/metrics-server-56c4f8c9d6-q86vt             1/1     Running     0          10s
pod/storage-provisioner                         1/1     Running     7          6d18h

NAME                                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
service/ingress-nginx-controller-admission   ClusterIP   10.108.226.190   <none>        443/TCP                  5d12h
service/kube-dns                             ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   6d18h
service/metrics-server                       ClusterIP   10.103.175.49    <none>        443/TCP                  10s

 

Saturday, March 13, 2021

Upgrade minikube on Fedora 33

 Upgrade Docker, kubectl, minikube to latest version

Remove previous versions and start minikube

Installed versions 

 

[dave@dave ~]$ kubectl version
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.4", GitCommit:"e87da0bd6e03ec3fea7933c4b5263d151aafd07c", GitTreeState:"clean", BuildDate:"2021-02-18T16:12:00Z", GoVersion:"go1.15.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:20:00Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
[dave@dave ~]$ docker version
Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:19:16 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:16:56 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[dave@dave ~]$ which kubectl
/usr/local/bin/kubectl
[dave@dave ~]$ minikube version
minikube version: v1.18.1
commit: 09ee84d530de4a92f00f1c5dbc34cead092b95bc


 

Delete all previous versions to avoid errors on start

Exiting due to GUEST_START: wait 6m0s for node: wait for healthy API server: controlPlane never updated to v1.20.2



[dave@dave ~]$ rm -rf ~/.minikube/

dave@dave ~]$ minikube delete
🙄  "minikube" profile does not exist, trying anyways.
💀  Removed all traces of the "minikube" cluster.
[dave@dave ~]$ minikube start --driver=docker
😄  minikube v1.18.1 on Fedora 33
✨  Using the docker driver based on user configuration
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
💾  Downloading Kubernetes v1.20.2 preload ...
    > preloaded-images-k8s-v9-v1....: 491.22 MiB / 491.22 MiB  100.00% 10.37 Mi
🔥  Creating docker container (CPUs=2, Memory=3900MB) ...
❗  Unable to create dedicated network, this might result in cluster IP change after restart: failed to create network after 20 attempts
🐳  Preparing Kubernetes v1.20.2 on Docker 20.10.3 ...
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v4
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default




Check minikube cluster

[dave@dave Downloads]$ kubectl cluster-info
Kubernetes master is running at https://172.17.0.3:8443
KubeDNS is running at https://172.17.0.3:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.


Sunday, February 21, 2021

JBoss Wildfly Kubernetes Operator

 HOWTO

 

GitHub repos


Build JBoss Wildfly Docker image GitHub repo https://github.com/dveselka/java-ee-8/tree/main/java-ee8-minimal Dockerfile
$ more Dockerfile
FROM jboss/wildfly

RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#123 --silent

COPY ./target/java-ee8-minimal.war /opt/jboss/wildfly/standalone/deployments/

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

Build Docker image

mvn clean package && docker build -t dveselka/java-ee8-minimal .
....

Sending build context to Docker daemon  111.6kB
Step 1/4 : FROM jboss/wildfly
latest: Pulling from jboss/wildfly
75f829a71a1c: Pull complete 
7b11f246b3d3: Pull complete 
b765648c2a58: Pull complete 
506aff4a9c5a: Pull complete 
a7ae73eec52a: Pull complete 
Digest: sha256:c0be1b7462a7ee9d07be5e319f7f2b10a93e5b43d51532ed012d2869e0224cf0
Status: Downloaded newer image for jboss/wildfly:latest
 ---> 13b4b5beba73
Step 2/4 : RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#123 --silent
 ---> Running in ecb1651c51fc
Removing intermediate container ecb1651c51fc
 ---> 74f6e50296e9
Step 3/4 : COPY ./target/java-ee8-minimal.war /opt/jboss/wildfly/standalone/deployments/
 ---> dd07d8a883fc
Step 4/4 : CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
 ---> Running in d9575f15ea43
Removing intermediate container d9575f15ea43
 ---> 01e0043e9e6f
Successfully built 01e0043e9e6f
Successfully tagged dveselka/java-ee8-minimal:latest

Docker image
[dave@dave java-ee8-minimal]$ docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
dveselka/java-ee8-minimal       latest              01e0043e9e6f        3 minutes ago       714MB

Push Docker image to DockerHub
$ docker push   dveselka/java-ee8-minimal
The push refers to repository [docker.io/dveselka/java-ee8-minimal]
4a24521ab9d6: Pushed 
348cd5508b6f: Pushed 
9ef61a25476f: Mounted from jboss/wildfly 
869989761eb2: Mounted from jboss/wildfly 
3fbe1e874b0d: Mounted from jboss/wildfly 
115463be137a: Mounted from jboss/wildfly 
613be09ab3c0: Mounted from jboss/wildfly 
latest: digest: sha256:d416275117d084e0cf557f6cf1ad82dc0aba7bf67921e4f19703e9a48701b2ec size: 1790

Run in k8s
$ kubectl run java-ee8-minimal --image=dveselka/java-ee8-minimal
Get k8s pods
 kubectl get pods
NAME               READY   STATUS             RESTARTS   AGE
java-ee8-minimal   0/1     ImagePullBackOff   0          12s
Minikube running in Docker
$ docker ps
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                                                                                                                                  NAMES
5f6397acb7e1        gcr.io/k8s-minikube/kicbase:v0.0.18   "/usr/local/bin/entr…"   21 hours ago        Up 22 minutes       127.0.0.1:32772->22/tcp, 127.0.0.1:32771->2376/tcp, 127.0.0.1:32770->5000/tcp, 127.0.0.1:32769->8443/tcp, 127.0.0.1:32768->32443/tcp   minikube

Start k8s dashboard
$ kubectl cluster-info 
Kubernetes control plane is running at https://172.17.0.2:8443
KubeDNS is running at https://172.17.0.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[dave@dave java-ee8-minimal]$ minikube dashboard
🔌  Enabling dashboard ...
    ▪ Using image kubernetesui/dashboard:v2.1.0
    ▪ Using image kubernetesui/metrics-scraper:v1.0.4
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:43609/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...

Forward k8s port to host
$ kubectl port-forward java-ee8-minimal 9990:9990
Forwarding from 127.0.0.1:9990 -> 9990
Forwarding from [::1]:9990 -> 9990
Handling connection for 9990

Check connection to app
$ wget http://localhost:8080/
--2021-03-14 17:28:48--  http://localhost:8080/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1504 (1.5K) [text/html]
Saving to: ‘index.html’

Call application resource
 curl http://localhost:8080/java-ee8-minimal/resources/ping
Enjoy Jakarta EE with MicroProfile 2+
Minikube dashboard with pod
Create deployment on k8s cluster
$ kubectl apply -f app.yml 
deployment.apps/java-ee8-minimal created
[dave@dave java-ee8-minimal]$ kubectl get pods
NAME                                READY   STATUS              RESTARTS   AGE
java-ee8-minimal-76cd57679d-l5smd   0/1     ContainerCreating   0          3s
java-ee8-minimal-76cd57679d-swvcd   0/1     ContainerCreating   0          3s

k8s deployment https://github.com/dveselka/java-ee-8/blob/main/java-ee8-minimal/app.yml
 more app.yml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: java-ee8-minimal
spec:
  selector:
    matchLabels:
      app: java-ee8
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: java-ee8
    spec:
      containers:
      - name: java-ee8-minimal
        image: dveselka/java-ee8-minimal
        ports:
        - containerPort: 8080

Check pods
[dave@dave java-ee8-minimal]$ kubectl get pods -l app=java-ee8 -o wide
NAME                                READY   STATUS    RESTARTS   AGE     IP           NODE       NOMINATED NODE   READINESS GATES
java-ee8-minimal-76cd57679d-l5smd   1/1     Running   0          3m35s   172.18.0.5   minikube   <none>           <none>
java-ee8-minimal-76cd57679d-swvcd   1/1     Running   0          3m35s   172.18.0.6   minikube   <none>           <none>

Export port - service https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/
dave@dave java-ee8-minimal]$ kubectl expose deployment/java-ee8-minimal
service/java-ee8-minimal exposed
[dave@dave java-ee8-minimal]$ curl 172.18.0.5:8080
curl: (7) Failed to connect to 172.18.0.5 port 8080: No route to host
[dave@dave java-ee8-minimal]$ kubectl get pods -l app=java-ee8 -o wide |grep podIP
[dave@dave java-ee8-minimal]$ kubectl get pods -l app=java-ee8 -o wide 
NAME                                READY   STATUS    RESTARTS   AGE     IP           NODE       NOMINATED NODE   READINESS GATES
java-ee8-minimal-76cd57679d-l5smd   1/1     Running   0          5m28s   172.18.0.5   minikube   <none>           <none>
java-ee8-minimal-76cd57679d-swvcd   1/1     Running   0          5m28s   172.18.0.6   minikube   <none>           <none>
[dave@dave java-ee8-minimal]$ kubectl get svc java-ee8-minimal
NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
java-ee8-minimal   ClusterIP   10.103.186.17   <none>        8080/TCP   35s
[dave@dave java-ee8-minimal]$ kubectl get svc java-ee8-minimal
NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
java-ee8-minimal   ClusterIP   10.103.186.17   <none>        8080/TCP   40s
[dave@dave java-ee8-minimal]$ kubectl get ep java-ee8-minimal
NAME               ENDPOINTS                         AGE
java-ee8-minimal   172.18.0.5:8080,172.18.0.6:8080   61s
[dave@dave java-ee8-minimal]$ curl 172.18.0.5:8080/java-ee8-minimal/resources/ping
curl: (7) Failed to connect to 172.18.0.5 port 8080: No route to host
[dave@dave java-ee8-minimal]$ kubectl exec my-nginx-3800858182-jr4a2 -- printenv | grep SERVICE^C
[dave@dave java-ee8-minimal]$ kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
java-ee8-minimal-76cd57679d-l5smd   1/1     Running   0          7m18s
java-ee8-minimal-76cd57679d-swvcd   1/1     Running   0          7m18s
[dave@dave java-ee8-minimal]$ kubectl exec java-ee8-minimal-76cd57679d-l5smd -- printenv | grep SERVICE
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_SERVICE_HOST=10.96.0.1
[dave@dave java-ee8-minimal]$ kubectl get services kube-dns --namespace=kube-system
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   26h
[dave@dave java-ee8-minimal]$ kubectl run curl --image=radial/busyboxplus:curl -i --tty
If you don't see a command prompt, try pressing enter.
[ root@curl:/ ]$ nslookup  java-ee8-minimal
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

nslookup: can't resolve 'java-ee8-minimal'
[ root@curl:/ ]$ curl 172.18.0.5:8080/java-ee8-minimal/resources/ping

Add ingress https://kubernetes.io/docs/concepts/services-networking/ingress/ https://github.com/dveselka/java-ee-8/blob/main/java-ee8-minimal/ingress.yaml
$ kubectl apply -f ingress.yaml 
ingress.networking.k8s.io/java-ee8-ingress configured
[dave@dave java-ee8-minimal]$ kubectl describe ingress  java-ee8-ingress
Name:             java-ee8-ingress
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *           
              /java-ee8-minimal   java-ee8-minimal:8080 (172.18.0.5:8080,172.18.0.6:8080)
Annotations:  nginx.ingress.kubernetes.io/rewrite-target: /
Events:       <none>

SSH into container inside k8s cluster

[dave@dave java-ee8-minimal]$ kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
curl                                1/1     Running   1          3h49m
java-ee8-minimal-76cd57679d-l5smd   1/1     Running   0          3h58m
java-ee8-minimal-76cd57679d-swvcd   1/1     Running   0          3h58m
[dave@dave java-ee8-minimal]$ kubectl exec --stdin --tty java-ee8-minimal-76cd57679d-l5smd  -- /bin/bash
[jboss@java-ee8-minimal-76cd57679d-l5smd ~]$ curl localhost:8080/java-ee8-minimal/resources/ping
Enjoy Jakarta EE with MicroProfile 2+!
Add JBOss Wildfly admin user
[jboss@java-ee8-minimal-76cd57679d-l5smd ~]$ cd wildfly/
[jboss@java-ee8-minimal-76cd57679d-l5smd wildfly]$ ls
LICENSE.txt  README.txt  appclient  bin  copyright.txt  docs  domain  jboss-modules.jar  modules  standalone  welcome-content
[jboss@java-ee8-minimal-76cd57679d-l5smd wildfly]$ cd bin
[jboss@java-ee8-minimal-76cd57679d-l5smd bin]$ ./add-user.sh

What type of user do you wish to add? 
 a) Management User (mgmt-users.properties) 
 b) Application User (application-users.properties)
(a): 

Access Wildfly admin console Forward admin port
$ kubectl port-forward  java-ee8-minimal-76cd57679d-l5smd 9990:9990
Forwarding from 127.0.0.1:9990 -> 9990
Forwarding from [::1]:9990 -> 9990
Handling connection for 9990

Access console via browser using
http://localhost:9990/console
Access JBoss using minikube service
$ minikube service java-ee8-service
|-----------|------------------|-------------|-------------------------|
| NAMESPACE |       NAME       | TARGET PORT |           URL           |
|-----------|------------------|-------------|-------------------------|
| default   | java-ee8-service |        8080 | http://172.17.0.2:30919 |
|-----------|------------------|-------------|-------------------------|
🎉  Opening service default/java-ee8-service in default browser...

Instance running at http://172.17.0.2:30919/
$ wget -O - http://172.17.0.2:30919 
--2021-03-20 09:33:06--  http://172.17.0.2:30919/
Connecting to 172.17.0.2:30919... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1504 (1.5K) [text/html]
Saving to: ‘STDOUT’

-                                         0%[                                                                                ]       0  --.-KB/s               <!DOCTYPE html>

<html>
<head>
    <!-- proper charset -->
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

    <title>Welcome to WildFly</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="StyleSheet" href="wildfly.css" type="text/css">
</head>

<body>
<div class="wrapper">
    <div class="content">
        <div class="logo">
                <img src="wildfly_logo.png" alt="WildFly" border="0" />
        </div>
        <h1>Welcome to WildFly</h1>

        <h3>Your WildFly instance is running.</h3>

        <p><a href="https://docs.wildfly.org">Documentation</a> | <a href="https://github.com/wildfly/quickstart">Quickstarts</a> | <a href="/console">Administration
            Console</a> </p>

        <p><a href="https://wildfly.org">WildFly Project</a> |
            <a href="https://community.jboss.org/en/wildfly">User Forum</a> |
            <a href="https://issues.jboss.org/browse/WFLY">Report an issue</a></p>
        <p class="logos"><a href="https://www.jboss.org"><img src="jbosscommunity_logo_hori_white.png" alt="JBoss and JBoss Community" width=
                "195" height="37" border="0"></a></p>

        <p class="note">To replace this page simply deploy your own war with / as its context path.<br />
            To disable it, remove the "welcome-content" handler for location / in the undertow subsystem.</p>
    </div>
</div>
</body>
</html>
-                                       100%[===============================================================================>]   1.47K  --.-KB/s    in 0s      

2021-03-20 09:33:06 (36.7 MB/s) - written to stdout [1504/1504]

Weblogic Kubernetes Operator

HOWTO

 

GitHub repos

Saturday, February 13, 2021

Docker network between standalone containers

 HOWTO

 

GitHub repo

https://github.com/dveselka/weblogic/tree/master/docker-compose-managed-server

Containers

 

 docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                            NAMES
bb6155b895af        12214-weblogic-domain-generic   "/u01/oracle/contain…"   3 minutes ago       Up 3 minutes        0.0.0.0:8001->8001/tcp                           managedserver
edc43bd0ce1c        12214-weblogic-domain-generic   "/u01/oracle/contain…"   3 minutes ago       Up 3 minutes        0.0.0.0:7001->7001/tcp, 0.0.0.0:9002->9002/tcp   adminserver

 

 Ping adminserver by hostname from managed server

$ docker exec -it managedserver /bin/bash
[oracle@bb6155b895af ~]$ ping adminserver
PING adminserver (172.19.0.2) 56(84) bytes of data.
64 bytes from adminserver.docker-compose-managed-server_wlsnet (172.19.0.2): icmp_seq=1 ttl=64 time=0.143 ms
64 bytes from adminserver.docker-compose-managed-server_wlsnet (172.19.0.2): icmp_seq=2 ttl=64 time=0.126 ms

Docker networks

 

[dave@dave ~]$ docker network ls
NETWORK ID          NAME                                   DRIVER              SCOPE
f52862010f16        bridge                                 bridge              local
4d18d28369b0        docker-compose-managed-server_wlsnet   bridge              local
fc58b29d0364        docker-compose_wlsnet                  bridge              local
f17fcc698c57        host                                   host                local
17497f49dcb2        none                                   null                local

 

Docker network for Weblogic servers

[dave@dave ~]$ docker inspect docker-compose-managed-server_wlsnet
[
    {
        "Name": "docker-compose-managed-server_wlsnet",
        "Id": "4d18d28369b0ec5dae676239ab95a3f64a2389091f0b47929aec9ca19e4b958b",
        "Created": "2021-02-13T08:46:13.300367764+01:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.19.0.0/16",
                    "Gateway": "172.19.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "bb6155b895af6f96341d1526d6e08597b3aab2156e29e1b8f90f980b44f0d198": {
                "Name": "managedserver",
                "EndpointID": "455729a26be89f9d37dde62a8b4b8e8a8fccfe248ee2425e574fb6f82ffa7ecb",
                "MacAddress": "02:42:ac:13:00:03",
                "IPv4Address": "172.19.0.3/16",
                "IPv6Address": ""
            },
            "edc43bd0ce1cee7f9d1b9cc9a32b9868396794a9b0e6ab32196ac32aec04ac31": {
                "Name": "adminserver",
                "EndpointID": "3744588006fc91c958625a115b2db839fe7dd5c601f774d9b648d717ba300dd9",
                "MacAddress": "02:42:ac:13:00:02",
                "IPv4Address": "172.19.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "wlsnet",
            "com.docker.compose.project": "docker-compose-managed-server",
            "com.docker.compose.version": "1.27.4"
        }
    }
]

Weblogic servers