0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

気軽にJavaのコード検証したいだけ

Last updated at Posted at 2023-02-03

はじめに

「気軽にJavaの勉強がしたいよ~」と思ったわけです。

前提環境

・M1 Mac mini
・docker
・kubernetes

コンテナ作成

Dockerfileを作成しました。

M1 Mac mini (%はMacOSのシェルプロンプト)
% vi Dockerfile
Dockerfile
FROM ubuntu:jammy
ARG DEBIAN_FRONTEND=noninteractive

RUN apt update &&\
    apt upgrade -y
RUN apt install -y \
    python3 \
    python3-pip \
    openjdk-11-jdk \
    git \
&&  ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
&&  apt clean \
&&  rm -rf /var/lib/apt/lists/*

ENV TZ=Asia/Tokyo

RUN pip3 install --no-cache-dir \
    jupyterlab \
    jupyterlab_code_formatter \
    jupyterlab-git \
    jupyterlab_widgets \
    jupyterlab-language-pack-ja-JP

RUN git clone https://github.com/SpencerPark/IJava.git &&\
    cd IJava/ &&\
    ./gradlew installKernel

CMD ["jupyter-lab","--allow-root","--ip=0.0.0.0","--port=8888","--no-browser","--NotebookApp.token=''"]

buildします。

M1 Mac mini
% docker build -t jupyterlab:latest .

そのままdockerで使うなら以下のコマンドで。

M1 Mac mini
% docker run --rm -p 8888:8888 -it jupyterlab:latest

コードや設定を保存したいならどこかのディレクトリをボリュームマウントしてください。

kubernetesで使う

kubernetes用のレジストリに突っ込みます。

M1 Mac mini
% docker build -t 10.0.0.1:30500/jupyterlab:latest .
% docker push 10.0.0.1:30500/jupyterlab:latest

namespaceを作って、podとsvcをapplyします。

kubernetes
$ kubectl create namespace jupyterlab
$ vi jupyterlab-pod.yaml
jupyterlab-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: jupyterlab
  namespace: jupyterlab
  labels:
    app: jupyterlab
spec:
  containers:
  - name: jupyterlab
    image: 10.0.0.1:30500/jupyterlab:latest
    resources:
      requests:
        cpu: 1
        memory: 1.5Gi
      limits:
        cpu: 1
        memory: 1.5Gi
    ports:
    - name: jupyterlab
      containerPort: 8888
kubernetes
$ kubectl apply -f jupyterlab-pod.yaml
$ vi jupyterlab-svc.yaml
jupyterlab-svc.yaml
apiVersion: v1
kind: Service

metadata:
  name: jupyterlab
  namespace: jupyterlab
  labels:
    app: jupyterlab
spec:
  type: NodePort
  ports:
    - name: http
      port: 8888
      targetPort: 8888
      nodePort: 31888
  selector:
    app: jupyterlab
kubernetes
$ kubectl apply -f jupyterlab-svc.yaml

おわりに

NotebookでJavaが使えます。
コードはある程度適当(import書かず)でも動きますし、逐一コンパイルしなくていいのは楽です。
FnkiaevaQAAaGZx.jfif

簡単なコード検証したいだけなので、これで満足です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?