kubectl autocompletion on windows & git bash

Hits: 24

Write bash completion code to a file

kubectl completion bash > ~/.kube/completion.bash.inc

and source it from .bash_profile

printf "
# Kubectl shell completion
source '$HOME/.kube/completion.bash.inc'
" >> $HOME/.bash_profile

load the kubectl completion for bash in to current shell

source $HOME/.bash_profile

How to develop PHP applications on Local Kubernetes with Helm

Hits: 35

Dont Worry! It is Very Easy.. πŸ™‚

Install the Helm CLI and k3s(/or minikube) as kubernetes before the begin.

  1. Create Project Tree with empty File Content like so:
.
β”œβ”€β”€ Chart.yaml
β”œβ”€β”€ project
β”‚   └── index.php
β”œβ”€β”€ templates
β”‚   β”œβ”€β”€ deployment.yaml
β”‚   β”œβ”€β”€ ingress.yaml
β”‚   β”œβ”€β”€ pvc.yaml
β”‚   β”œβ”€β”€ pv.yaml
β”‚   └── service.yaml
└── values.yaml

now let’s fill in the files.

Read more

Chart.yaml

apiVersion: v2
name: myfirstlocalphpwithkubernetes
description: A Helm chart for local PHP Development on local Kubernetes

# A chart can be either an 'application' or a 'library' chart.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. 
appVersion: "1.16.0"

project/index.php

<?php

echo "My First local PHP with Kubernetes via Helm";

templates/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-deployment
  labels:
        app: {{ .Release.Name }}-php
spec:
  selector:
    matchLabels:
      app: {{ .Release.Name }}-php
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}-php
    spec:
      containers:
      - image: {{ .Values.image.name }}:{{ .Values.image.tag }}
        name: {{ .Release.Name }}-php
        imagePullPolicy: Always
        ports:
          - containerPort: 80
        volumeMounts:
          - name: {{ .Release.Name }}-php-storage
            mountPath: {{ .Values.mountPath }}
      volumes:
        - name: {{ .Release.Name }}-php-storage
          persistentVolumeClaim:
            claimName: {{ .Release.Name }}-pvc-php

templates/ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ .Release.Name }}-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx-example
  rules:
  - host: {{ .Values.hostname }}
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: {{ .Release.Name }}-php-service
            port:
              number: 80

template/pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name:  pv-{{ .Release.Name }}-php
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: {{ .Values.hostPath }}

template/pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
    name: {{ .Release.Name }}-pvc-php
spec:
    storageClassName: manual
    accessModes:
        - ReadWriteOnce
    resources:
        requests:
            storage: 1Gi

template/service.yaml

apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-php-service
spec:
  type: LoadBalancer
  selector:
    app: {{ .Release.Name }}-php
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 80
      targetPort: 80
      # Optional field

values.yaml

hostname: 'simple-php.local'
mountPath: 'var/www/html/'
hostPath: '/home/projects/myfirstlocalphpwithkubernetes/project'
image:
  name: php
  tag: 8.1-apache

and let’s install with helm

d8dev@d8devs:~/projects/myfirstlocalphpwithkubernetes$ helm install -f values.yaml myfirstlocalphp .

Add hostname (simple-php.local) a.k.a domain in your /etc/hosts with any text editor.

My /etc/hosts looking so;

d8dev@d8devs:~/projects/myfirstlocalphpwithkubernetes$ cat /etc/hosts
127.0.0.1       localhost
127.0.1.1       simple-php.local
......
.....

And check the domain in your browser with slash ( http://simple-php.local/ )

Enjoy!

Cert-Manager – Kubernetes NGINX Ingress with Cert-Manager

Hits: 200

Install

Cert-manager is easy to install with Helm Package Manager. The first step is add Jetstack repository in our repository and becoming the package info with update

helm repo add jetstack https://charts.jetstack.io
helm repo update

Now we can install Cert-Manager with CRDs into our cluster:

helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true

Cert-manager have also a kubectl plugin to easily manage configs and resources

OS=$(go env GOOS); ARCH=$(go env GOARCH); curl -sSL -o kubectl-cert-manager.tar.gz https://github.com/cert-manager/cert-manager/releases/download/v1.7.2/kubectl-cert_manager-$OS-$ARCH.tar.gz
tar xzf kubectl-cert-manager.tar.gz
sudo mv kubectl-cert_manager /usr/local/bin

Configure for The Let’s Encrypt Certificate

Continue reading “Cert-Manager – Kubernetes NGINX Ingress with Cert-Manager”

Pod Volume via hostPath via Minikube-Docker on Apple M1

Hits: 88

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!

Gitea Installation via Helm on Apple M1

Hits: 103

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.