Pod Volume via hostPath via Minikube-Docker on Apple M1

Hits: 113

Actually Docker Desktop App as default sharing Users, private etc. folder with Docker Images.

Github Repo for Example Project: https://github.com/kzorluoglu/localphp8nginxwithhelm

But Minikube need minikube mount bidirectional folder sync. From this reason i will say, use your own simple folder structure for Minikube hostPath Solution. For example:

Macbook Folder: $home/minikubeprojects
Minikube Cluster: mnt1/minikubeprojects

For mounting, you need after minikube start only this

 korayzorluoglu@MBP-von-Koray ~ % minikube mount $HOME/minikubeprojects:/mnt1/minikubeprojects

Example Configuration

Project / chart / values.yaml

mountPath: /var/www/html
nginx:
  image: nginx:1.14.2

php:
  image: php:8.1-rc-fpm-alpine

Project / chart / templates / deployments.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: php8-project-deployment
  labels:
    app: php8-project-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: php8-project-deployment
  template:
    metadata:
      labels:
        app: php8-project-deployment
    spec:
      volumes:
        # Create the shared files volume to be used in both pods
        - name: php8-project-pv-storage
          persistentVolumeClaim:
            claimName: php8-project-pv-claim
        # Add the ConfigMap we declared above as a volume for the pod
        - name: nginx-config-volume
          configMap:
            name: php8-project-nginx-config
      containers:
        - name: php8-project-nginx
          image: {{ .Values.nginx.image }}
          ports:
            - containerPort: 80
          volumeMounts:
            - name: php8-project-pv-storage
              mountPath: {{ .Values.mountPath }}
            - name: nginx-config-volume
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
          # Just spin & wait forever
          command: [ "/bin/bash", "-c", "--" ]
          args: [ "while true; do sleep 30; done;" ]
        - name: php
          image: {{ .Values.php.image }}
          volumeMounts:
            - name: php8-project-pv-storage
              mountPath: {{ .Values.mountPath }}

Project / chart / templates / volume.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: php8-project-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt1/minikubeprojects/php8/app"

---

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: php8-project-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 3Gi

Project / chart / templates / configmap.yaml

kind: ConfigMap
apiVersion: v1
metadata:
  name: php8-project-nginx-config
data:
  nginx.conf: |
    events {
    }
    http {
      server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # Set nginx to serve files from the shared volume!
        root {{ .Values.mountPath }};
        server_name _;
        location / {
          try_files $uri $uri/ =404;
        }
        location ~ \.php$ {
          include fastcgi_params;
          fastcgi_param REQUEST_METHOD $request_method;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_pass 127.0.0.1:9000;
        }
      }
    }

do you need mount directoy check? for that, check the minikube directory and pod directory, or the pod details via kubectl pod describe your-chart-name

korayzorluoglu@MBP-von-Koray chart % minikube ssh && cd /mnt1/minikubeprojects && tree

Enjoy!

Kubernetes Port Forwarding with kubefwd on Apple M1

Hits: 650

kubefwd is a command line tool for Kubernetes Services and allows you to access any service from your local workstation in the same namespace on cluster. kubefwd temporally adds domain records to our /etc/hosts file with the service names it forwards.

Here is explaining the workflow from official GitHub repository:

https://github.com/txn2/kubefwd

and Screencast (it’s also from GitHub repository)

https://github.com/txn2/kubefwd

Installation with homebrew

  1. Requirement
    1. kubectl kubefwd assumes you have kubectl installed and configured with cluster access.

You can install kubefwd directly from txn2/tap.

brew install txn2/tap/kubefwd

To upgrade:

brew upgrade kubefwd

Testing

Create and run forwarding

Open Gitea-Service and install it. After installation i have a new repo created and my ssh key in to the my gitea profile added.

Cloning, Pushing…

Gitea Dashboard

Kubectl Autocomplete on MacOS

Hits: 159

vim ~/.zshrc
alias k=kubectl
autoload -U +X compinit && compinit
[[ /usr/local/bin/kubectl ]] && source <(kubectl completion zsh)

esc > wq > enter

Gitea Installation via Helm on Apple M1

Hits: 134

Gitea? is aa community developed and managed simple, lightweight github alternative, written in Go.

Gitea provides a Helm Cart for installation on kubernetes, thats mean, if we would like to customize our install, we can do this.. But when not, we can directly use without any custom configuration/helm config.

Installation

helm repo add gitea-charts https://dl.gitea.io/charts/
helm repo update && helm install gitea gitea-charts/gitea
MBP-von-Koray ~ % helm repo update && helm install gitea gitea-charts/gitea
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "gitea-charts" chart repository
Update Complete. ⎈Happy Helming!⎈
NAME: gitea
LAST DEPLOYED: Sun Aug  1 14:07:36 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  echo "Visit http://127.0.0.1:3000 to use your application"
  kubectl --namespace default port-forward svc/gitea-http 3000:3000

And starting port-forwarding for Port 3000.

kubectl --namespace default port-forward svc/gitea-http 3000:3000

and here is.. Enjoy 😊

To customize your install, here is the complete configuration details.

Helm CLI installation on Apple M1

Hits: 5912

Helm? is a package manager for Kubernetes. Helm uses a packaging format, this called “charts”.

Chart? is a collection of files, what be describe Kubernetes resources, like a Server, Database, Caches or simple deploy pod.

Check first first which version as lastest for ARM64 released : https://github.com/helm/helm/releases.

Installation Step

Run following console commands in command line. IMPORTANT! Don’t Forget replacing this LASTEST-RELEASE-HERE tag with latest release/version from https://github.com/helm/helm/releases. For example

  • Download your Helm CLI Binary
curl -O https://get.helm.sh/helm-LASTEST-RELEASE-HERE-darwin-arm64.tar.gz
  • Unpack it
tar -zxvf helm-LASTEST-RELEASE-HERE-linux-amd64.tar.gz
  • And Move it to bin location
sudo mv darwin-arm64/helm /usr/local/bin/helm

and, you should be able to run, check with this command and see the output

koray@MBP-von-Koray ~ % helm help
The Kubernetes package manager

Common actions for Helm:

- helm search:    search for charts
- helm pull:      download a chart to your local directory to view
- helm install:   upload the chart to Kubernetes
- helm list:      list releases of charts

Environment variables:

| Name                               | Description                                                                       |
|------------------------------------|-----------------------------------------------------------------------------------|
| $HELM_CACHE_HOME                   | set an alternative location for storing cached files.                             |
| $HELM_CONFIG_HOME                  | set an alternative location for storing Helm configuration.                       |
| $HELM_DATA_HOME                    | set an alternative location for storing Helm data.                                |
| $HELM_DEBUG                        | indicate whether or not Helm is running in Debug mode                             |
| $HELM_DRIVER                       | set the backend storage driver. Values are: configmap, secret, memory, postgres   |
........
......
.....

Example Steps with Today’s version

koray@MBP-von-Koray ~ % curl -O https://get.helm.sh/helm-v3.6.3-darwin-arm64.tar.gz
koray@MBP-von-Koray ~ % tar -zxvf helm-v3.6.3-darwin-arm64.tar.gz 
koray@MBP-von-Koray ~ % sudo mv darwin-arm64/helm /usr/local/bin/helm