ラベル ApacheHttpd の投稿を表示しています。 すべての投稿を表示
ラベル ApacheHttpd の投稿を表示しています。 すべての投稿を表示

2022年3月27日日曜日

k3sでlocal永続ボリュームを使用するApache Httpdをデプロイする

k3sでlocal永続ボリュームを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. テスト用ページの作成
k3sホストにテスト用ページを作成します。
sudo mkdir -p /var/mywww/html

echo '<html><head><title>sample</title></head><body>sample.</body></html>' | sudo tee /var/mywww/html/index.html

2.local永続ボリュームの作成
以下のコマンドを実行してlocal永続ボリュームを作成します
cat << EOF > local-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-httpd-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadOnlyMany
  storageClassName: local-storage
  local:
    path: /var/mywww/html
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - `hostname`
EOF
※`hostname`は今ログオンしているk3sがインストールされているホスト名になります。適宜変更してください。
sudo k3s kubectl apply -f ./local-httpd-pv.yml

3. 永続ボリューム要求の作成
以下のコマンドを実行してlocal永続ボリューム要求を作成します
cat << EOF > local-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: local-storage
  resources:
    requests:
      storage: 5Gi
  volumeName: local-httpd-pv
EOF

sudo k3s kubectl apply -f ./local-httpd-pvc.yml

4. Deploymentの作成
以下のコマンドでhttpd:2.4-alipineのイメージと作成したlocal永続ボリュームを使用するDeploymentを作成します。
cat << EOF > httpd-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: myhttpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myhttpd
  template:
    metadata:
      labels:
        app: myhttpd
    spec:
      containers:
      - name: myhttpd
        image: httpd:2.4-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - name: documentroot
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: documentroot
        persistentVolumeClaim:
          claimName: local-httpd-pvc
EOF

sudo k3s kubectl apply -f ./httpd-deployment.yml

5. サービスの作成
以下のコマンドでサービスを作成します。
cat << EOF > httpd-service.yml
apiVersion: v1
kind: Service
metadata:
  name: httpd-service
spec:
  selector:
    app: myhttpd
  type: LoadBalancer
  externalIPs:
  - xxx.xxx.xxx.xxx # 外部からアクセスできるk3sをインストールしたホストのIPを設定します。
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 80
EOF

sudo k3s kubectl apply -f ./httpd-service.yml

ブラウザからhttp://<ホスト名:8080/ にアクセスします

2022年3月5日土曜日

Microk8sでlocal永続ボリュームを使用するApache Httpdをデプロイする

Microk8sでlocal永続ボリュームを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. テスト用ページの作成
Microk8sホストにテスト用ページを作成します。
sudo mkdir -p /var/mywww/html

echo '<html><head><title>sample</title></head><body>sample.</body></html>' | sudo tee /var/mywww/html/index.html

2.local永続ボリュームの作成
以下のコマンドを実行してlocal永続ボリュームを作成します
cat << EOF > local-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-httpd-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadOnlyMany
  storageClassName: local-storage
  local:
    path: /var/mywww/html
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - `hostname`
EOF
#`hostname`は今ログオンしているMicrok8sがインストールされているホスト名になります。適宜変更してください。
microk8s kubectl apply -f ./local-httpd-pv.yml

3. 永続ボリューム要求の作成
以下のコマンドを実行してlocal永続ボリューム要求を作成します
cat << EOF > local-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: local-storage
  resources:
    requests:
      storage: 5Gi
  volumeName: local-httpd-pv
EOF

microk8s kubectl apply -f ./local-httpd-pvc.yml

4. Deploymentの作成
以下のコマンドでhttpd:2.4-alipineのイメージと作成したlocal永続ボリュームを使用するDeploymentを作成します。
cat << EOF > httpd-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: myhttpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myhttpd
  template:
    metadata:
      labels:
        app: myhttpd
    spec:
      containers:
      - name: myhttpd
        image: httpd:2.4-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - name: documentroot
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: documentroot
        persistentVolumeClaim:
          claimName: local-httpd-pvc
EOF

microk8s kubectl apply -f ./httpd-deployment.yml

5. サービスの作成
以下のコマンドでサービスを作成します。
cat << EOF > httpd-service.yml
apiVersion: v1
kind: Service
metadata:
  name: httpd-service
spec:
  selector:
    app: myhttpd
  type: LoadBalancer
  externalIPs:
  - xxx.xxx.xxx.xxx # 外部からアクセスできるMicrok8sをインストールしたホストのIPを設定します。
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 80
EOF

microk8s kubectl apply -f ./httpd-service.yml

ブラウザからhttp://<ホスト名>:8080/ にアクセスします

2022年2月12日土曜日

Microk8sとHelmでlocal永続ボリュームを使用するApache Httpdをデプロイする

Microk8sとHelmでlocal永続ボリュームを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. 以下のコマンドを実行して、外部からアクセスできるようにします。
microk8s enable dns

microk8s enable metallb
※IPの範囲を入力します

1. テスト用ページの作成
Microk8sにテスト用ページを作成します。
sudo mkdir -p /var/mywww/html

echo '<html><head><title>sample</title></head><body>helm sample.</body></html>' | sudo tee /var/mywww/html/index.html

2.local永続ボリュームの作成
以下のコマンドを実行してlocal永続ボリュームを作成します
cat << EOF > local-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-httpd-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadOnlyMany
  storageClassName: local-storage
  local:
    path: /var/mywww/html
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - `hostname`
EOF
※`hostname`は今ログオンしているMicrok8sがインストールされているホスト名になります。適宜変更してください。

microk8s kubectl apply -f ./local-httpd-pv.yml

3. 永続ボリューム要求の作成
以下のコマンドを実行してlocal永続ボリューム要求を作成します
cat << EOF > local-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: local-storage
  resources:
    requests:
      storage: 5Gi
  volumeName: local-httpd-pv
EOF

microk8s kubectl apply -f ./local-httpd-pvc.yml

4. HelmでApacheのインストール
以下のコマンドでbitnamiのApache Httpdをインストールします。htdocsPVCパラメータで使用する永続ボリューム要求を指定します。
microk8s helm3 repo update

microk8s helm3 install my-httpd bitnami/apache --set htdocsPVC=local-httpd-pvc --set service.loadBalancerIP=xxx.xxx.xxx.xxx --set service.ports.http=8080 --set service.ports.https=8443

※その他のパラメータについては、以下のbitnami apacheのgithubリポジトリを参照してください
https://github.com/bitnami/charts/tree/master/bitnami/apache

ブラウザからhttp://<ホスト名:8080/ にアクセスします

※アンインストールする時には以下のコマンドを実行します。
microk8s helm3 uninstall my-httpd

2022年2月10日木曜日

Microk8sでGlusterFSの永続ストレージを使用するApache Httpdをデプロイする

Microk8sでGlusterFSの永続ストレージを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. Microk8sをインストールしたホスト上でのGlusterfs準備
※GlusterFSクラスターは事前に準備しておきます。

※Microk8sホスト内の/etc/hostsにエントリを追加
echo 'xxx.xxx.xxx.xxx glusternode1' | sudo tee -a /etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode2' | sudo tee -a /etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode3' | sudo tee -a /etc/hosts
IPアドレスとホスト名は適宜変更してください。

sudo apt-get update && sudo apt-get install -y glusterfs-client

2. テスト用ページの作成
Glusterfsサーバーのホストにテスト用ページを作成します。
echo '<html><head><title>sample</title></head><body>contents on GlusterFS server.</body></html>' | sudo tee /glusterfs/index.html
※パスなどは適宜変更してください

3. Endpointsの作成
以下のIPアドレスを適宜変更して、Endpointsを作成します。
cat << EOF > glusterfs-endpoints.yml
apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
EOF

microk8s kubectl apply -f ./glusterfs-endpoints.yml

4. 永続ボリュームの作成
以下のGlusterFSボリューム名(myvolumeの部分)を変更して、永続ボリュームを作成します。
cat << EOF > glusterfs-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-httpd-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadOnlyMany
  storageClassName: slow
  glusterfs:
    endpoints: glusterfs-cluster
    path: myvolume
    readOnly: false
EOF

microk8s kubectl apply -f ./glusterfs-httpd-pv.yml

5. 永続ボリューム要求の作成
以下のコマンドを実行して、永続ボリューム要求を作成します。
cat << EOF > glusterfs-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: slow
  resources:
    requests:
      storage: 2Gi
  volumeName: glusterfs-httpd-pv
EOF

microk8s kubectl apply -f ./glusterfs-httpd-pvc.yml

6. Deploymentの作成
以下のコマンドを実行してDeploymentを作成します。
cat << EOF > glusterfs-httpd-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: myhttpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myhttpd
  template:
    metadata:
      labels:
        app: myhttpd
    spec:
      containers:
      - name: myhttpd
        image: httpd:2.4-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - name: documentroot
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: documentroot
        persistentVolumeClaim:
          claimName: glusterfs-httpd-pvc
EOF

microk8s kubectl apply -f ./glusterfs-httpd-deployment.yml

7. サービスの作成
以下のコマンドを実行してサービスを作成します。
cat << EOF > httpd-service.yml
apiVersion: v1
kind: Service
metadata:
  name: httpd-service
spec:
  selector:
    app: myhttpd
  type: LoadBalancer
  externalIPs:
  - xxx.xxx.xxx.xxx # 外部からアクセスできるMicrok8sをインストールしたホストのIPを設定します。
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 80
EOF

microk8s kubectl apply -f ./httpd-service.yml

ブラウザからhttp://<ホスト名:8080/ にアクセスします

2022年2月9日水曜日

Microk8sでNFS上の永続ストレージを使用するApache Httpdをデプロイする

Microk8sでNFS上の永続ストレージを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. テスト用ページの作成
NFSサーバーのホストにテスト用ページを作成します。
sudo mkdir -p /shared_dir/html

echo '<html><head><title>sample</title></head><body>contents on NFS server.</body></html>' | sudo tee /shared_dir/html/index.html

2.永続ボリュームの作成
以下のコマンドで、NFSサーバ上の永続ストレージを作成します。
cat << EOF > nfs-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-httpd-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadOnlyMany
  storageClassName: slow
  nfs:
    server: ※NFSサーバのIPアドレス
    path: "/shared_dir/html" ※NFSサーバのパス
  mountOptions:
    - nfsvers=4.2
EOF

microk8s kubectl apply -f ./nfs-httpd-pv.yml

3. 永続ボリューム要求の作成
以下のコマンドで、永続ストレージ要求を作成します。
cat << EOF > nfs-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: slow
  resources:
    requests:
      storage: 2Gi
  volumeName: nfs-httpd-pv
EOF

microk8s kubectl apply -f ./nfs-httpd-pvc.yml

4. Deploymentの作成
以下のコマンドでhttpd:2.4-alipineのイメージと作成したNFS上の永続ボリュームを使用するDeploymentを作成します。
cat << EOF > httpd-nfs-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: myhttpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myhttpd
  template:
    metadata:
      labels:
        app: myhttpd
    spec:
      containers:
      - name: myhttpd
        image: httpd:2.4-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - name: documentroot
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: documentroot
        persistentVolumeClaim:
          claimName: nfs-httpd-pvc
EOF

microk8s kubectl apply -f ./httpd-nfs-deployment.yml

5. サービスの作成
以下のコマンドでサービスを作成します。
cat << EOF > httpd-service.yml
apiVersion: v1
kind: Service
metadata:
  name: httpd-service
spec:
  selector:
    app: myhttpd
  type: LoadBalancer
  externalIPs:
  - xxx.xxx.xxx.xxx # 外部からアクセスできるMicrok8sをインストールしたホストのIPを設定します。
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 80
EOF

microk8s kubectl apply -f ./httpd-service.yml

ブラウザからhttp://<ホスト名:8080/ にアクセスします

2022年1月28日金曜日

MinikubeとHelmでGlusterFS上の永続ボリュームを使用するApache Httpdをデプロイする

MinikubeとHelmでGlusterFS上の永続ボリュームを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. MinikubeでのGlusterfs準備
※GlusterFSクラスターは事前に準備しておきます。

※minikube内の/etc/hostsにエントリを追加するためのファイルにエントリ追加
mkdir -p ~/.minikube/files/etc
echo 'xxx.xxx.xxx.xxx glusternode1' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode2' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode3' >> ~/.minikube/files/etc/hosts
IPアドレスとホスト名は適宜変更してください。

※minikube内にglusterfs-clientをインストールする
minikube ssh
sudo apt-get update && sudo apt-get install -y glusterfs-client
exit

2. テスト用ページの作成
Glusterfsサーバーのホストにテスト用ページを作成します。
echo '<html><head><title>sample</title></head><body>contents on GlusterFS server.</body></html>' | sudo tee /glusterfs/index.html
※パスなどは適宜変更してください

3. Endpointsの作成
以下のIPアドレスを適宜変更して、Endpointsを作成します。
cat << EOF > glusterfs-endpoints.yml
apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
EOF

kubectl apply -f ./glusterfs-endpoints.yml

4. 永続ボリュームの作成
以下のGlusterFSボリューム名(myvolumeの部分)を変更して、永続ボリュームを作成します。
cat << EOF > glusterfs-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-httpd-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadOnlyMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: myvolume
    readOnly: false
EOF

kubectl apply -f ./glusterfs-httpd-pv.yml

5. 永続ボリューム要求の作成
以下のコマンドを実行して、永続ボリューム要求を作成します。
cat << EOF > glusterfs-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: ""
  resources:
    requests:
      storage: 2Gi
  volumeName: glusterfs-httpd-pv
EOF

kubectl apply -f ./glusterfs-httpd-pvc.yml

4. HelmでApacheのインストール
以下のコマンドでbitnamiのApache Httpdをインストールします。htdocsPVCパラメータで使用する永続ボリューム要求を指定します。
helm repo update

helm install my-httpd-apache bitnami/apache --set htdocsPVC=glusterfs-httpd-pvc

※その他のパラメータについては、以下のbitnami apacheのgithubリポジトリを参照してください
https://github.com/bitnami/charts/tree/master/bitnami/apache
5. Port-Fowardingで外部からアクセスできるようにする
以下のコマンドを実行して、外部からアクセスできるようにします。
kubectl port-forward --address 0.0.0.0 deployment/my-httpd-apache  8080:8080

ブラウザからhttp://<ホスト名:8080/ にアクセスします

※アンインストールする時には以下のコマンドを実行します。
helm uninstall my-httpd-apache

2022年1月27日木曜日

MinikubeとHelmでNFS上の永続ボリュームを使用するApache Httpdをデプロイする

MinikubeとHelmでNFS上の永続ボリュームを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. テスト用ページの作成
NFSサーバーのホストにテスト用ページを作成します。
sudo mkdir -p /shared_dir/html

echo '<html><head><title>sample</title></head><body>contents on NFS server.</body></html>' | sudo tee /shared_dir/html/index.html

2.永続ボリュームの作成
以下のコマンドで、NFSサーバ上の永続ストレージを作成します。
cat << EOF > nfs-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-httpd-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadOnlyMany
  nfs:
    server: ※NFSサーバのIPアドレス
    path: "/shared_dir/html" ※NFSサーバのパス
  mountOptions:
    - nfsvers=4.2
EOF

kubectl apply -f ./nfs-httpd-pv.yml

3. 永続ボリューム要求の作成
以下のコマンドで、永続ストレージ要求を作成します。
cat << EOF > nfs-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: ""
  resources:
    requests:
      storage: 2Gi
  volumeName: nfs-httpd-pv
EOF

kubectl apply -f ./nfs-httpd-pvc.yml

4. HelmでApacheのインストール
以下のコマンドでbitnamiのApache Httpdをインストールします。htdocsPVCパラメータで使用する永続ボリューム要求を指定します。
helm repo update

helm install my-httpd-apache bitnami/apache --set htdocsPVC=nfs-httpd-pvc

※その他のパラメータについては、以下のbitnami apacheのgithubリポジトリを参照してください
https://github.com/bitnami/charts/tree/master/bitnami/apache

5. Port-Fowardingで外部からアクセスできるようにする
以下のコマンドを実行して、外部からアクセスできるようにします。
kubectl port-forward --address 0.0.0.0 deployment/my-httpd-apache  8080:8080

ブラウザからhttp://<ホスト名:8080/ にアクセスします

※アンインストールする時には以下のコマンドを実行します。
helm uninstall my-httpd-apache

関連情報

Ubuntu 20.04にNFSサーバをインストールする

2022年1月26日水曜日

MinikubeとHelmでlocal永続ボリュームを使用するApache Httpdをデプロイする

MinikubeとHelmでlocal永続ボリュームを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. テスト用ページの作成
minikubeにテスト用ページを作成します。
minikube ssh

sudo mkdir -p /var/mywww/html

echo '<html><head><title>sample</title></head><body>sample.</body></html>' | sudo tee /var/mywww/html/index.html

exit

2.local永続ボリュームの作成
以下のコマンドを実行してlocal永続ボリュームを作成します
cat << EOF > local-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-httpd-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadOnlyMany
  storageClassName: local-storage
  local:
    path: /var/mywww/html
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - minikube
EOF

kubectl apply -f ./local-httpd-pv.yml

3. 永続ボリューム要求の作成
以下のコマンドを実行してlocal永続ボリューム要求を作成します
cat << EOF > local-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: local-storage
  resources:
    requests:
      storage: 5Gi
  volumeName: local-httpd-pv
EOF

kubectl apply -f ./local-httpd-pvc.yml

4. HelmでApacheのインストール
以下のコマンドでbitnamiのApache Httpdをインストールします。htdocsPVCパラメータで使用する永続ボリューム要求を指定します。

helm repo update

helm install my-httpd-apache bitnami/apache --set htdocsPVC=local-httpd-pvc

※その他のパラメータについては、以下のbitnami apacheのgithubリポジトリを参照してください
https://github.com/bitnami/charts/tree/master/bitnami/apache

5. Port-Fowardingで外部からアクセスできるようにする
以下のコマンドを実行して、外部からアクセスできるようにします。
kubectl port-forward --address 0.0.0.0 deployment/my-httpd-apache  8080:8080

ブラウザからhttp://<ホスト名:8080/ にアクセスします

※アンインストールする時には以下のコマンドを実行します。
helm uninstall my-httpd-apache

2022年1月25日火曜日

MinikubeでGlusterFSの永続ストレージを使用するApache Httpdをデプロイする

MinikubeでGlusterFSの永続ストレージを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. MinikubeでのGlusterfs準備
※GlusterFSクラスターは事前に準備しておきます。

※minikube内の/etc/hostsにエントリを追加するためのファイルにエントリ追加
mkdir -p ~/.minikube/files/etc
echo 'xxx.xxx.xxx.xxx glusternode1' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode2' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode3' >> ~/.minikube/files/etc/hosts
IPアドレスとホスト名は適宜変更してください。

※minikube内にglusterfs-clientをインストールする
minikube ssh
sudo apt-get update && sudo apt-get install -y glusterfs-client
exit

2. テスト用ページの作成
Glusterfsサーバーのホストにテスト用ページを作成します。
echo '<html><head><title>sample</title></head><body>contents on GlusterFS server.</body></html>' | sudo tee /glusterfs/index.html
※パスなどは適宜変更してください

3. Endpointsの作成
以下のIPアドレスを適宜変更して、Endpointsを作成します。
cat << EOF > glusterfs-endpoints.yml
apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
EOF

kubectl apply -f ./glusterfs-endpoints.yml

4. 永続ボリュームの作成
以下のGlusterFSボリューム名(myvolumeの部分)を変更して、永続ボリュームを作成します。
cat << EOF > glusterfs-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-httpd-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadOnlyMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: myvolume
    readOnly: false
EOF

kubectl apply -f ./glusterfs-httpd-pv.yml

5. 永続ボリューム要求の作成
以下のコマンドを実行して、永続ボリューム要求を作成します。
cat << EOF > glusterfs-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: ""
  resources:
    requests:
      storage: 2Gi
  volumeName: glusterfs-httpd-pv
EOF

kubectl apply -f ./glusterfs-httpd-pvc.yml

6. Deploymentの作成
以下のコマンドを実行してDeploymentを作成します。
cat << EOF > glusterfs-httpd-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: myhttpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myhttpd
  template:
    metadata:
      labels:
        app: myhttpd
    spec:
      containers:
      - name: myhttpd
        image: httpd:2.4-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - name: documentroot
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: documentroot
        persistentVolumeClaim:
          claimName: glusterfs-httpd-pvc
EOF

kubectl apply -f ./glusterfs-httpd-deployment.yml

7. サービスの作成
以下のコマンドを実行してサービスを作成します。
cat << EOF > httpd-service.yml
apiVersion: v1
kind: Service
metadata:
  name: httpd-service
spec:
  selector:
    app: myhttpd
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 80
EOF

kubectl apply -f ./httpd-service.yml

8. Port-Fowardingで外部からアクセスできるようにする
以下のコマンドを実行して、外部からアクセスできるようにします。
kubectl port-forward --address 0.0.0.0 service/httpd-service 8080:8080
ブラウザからhttp://<ホスト名:8080/ にアクセスします

2022年1月21日金曜日

Minikubeでlocal永続ボリュームを使用するApache Httpdをデプロイする

Minikubeでlocal永続ボリュームを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. テスト用ページの作成
minikubeのホストにテスト用ページを作成します。
minikube ssh

sudo mkdir -p /var/mywww/html

echo '<html><head><title>sample</title></head><body>sample.</body></html>' | sudo tee /var/mywww/html/index.html

exit

2.local永続ボリュームの作成
以下のコマンドを実行してlocal永続ボリュームを作成します
cat << EOF > local-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-httpd-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadOnlyMany
  storageClassName: local-storage
  local:
    path: /var/mywww/html
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - minikube
EOF

kubectl apply -f ./local-httpd-pv.yml

3. 永続ボリューム要求の作成
以下のコマンドを実行してlocal永続ボリューム要求を作成します

cat << EOF > local-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: local-storage
  resources:
    requests:
      storage: 5Gi
  volumeName: local-httpd-pv
EOF

kubectl apply -f ./local-httpd-pvc.yml

4. Deploymentの作成
以下のコマンドでhttpd:2.4-alipineのイメージと作成したlocal永続ボリュームを使用するDeploymentを作成します。
cat << EOF > httpd-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: myhttpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myhttpd
  template:
    metadata:
      labels:
        app: myhttpd
    spec:
      containers:
      - name: myhttpd
        image: httpd:2.4-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - name: documentroot
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: documentroot
        persistentVolumeClaim:
          claimName: local-httpd-pvc
EOF

kubectl apply -f ./httpd-deployment.yml

5. サービスの作成
以下のコマンドでサービスを作成します。
cat << EOF > httpd-service.yml
apiVersion: v1
kind: Service
metadata:
  name: httpd-service
spec:
  selector:
    app: myhttpd
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 80
EOF

kubectl apply -f ./httpd-service.yml

6. Port-Fowardingで外部からアクセスできるようにする
kubectl port-forward --address 0.0.0.0 service/httpd-service 8080:8080
ブラウザからhttp://<ホスト名:8080/ にアクセスします