Pages

Monday, April 10, 2023

NextCloud Setup with Docker

One of the most commonly used self-hosted alternatives for cloud storages. Now it's easy to deploy with dockers. Following docker file and Nginx configuration can be used to deploy the nextcloud application behind the Nginx proxy server with SSL termination. 
we can bring up and bring down the containers with the following commands

docket-compose up -f
docker-compose down

===========

version: '2'
#volumes:
#  nextcloud: /root/nextcloud/ncdata
#  db: /root/nextcloud/mysql
services:
  db:
    image: mariadb:10.5
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - /root/nextcloud/mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=XXXXXXXXX
      - MYSQL_PASSWORD=XXXXXXXX
      - MYSQL_DATABASE=XXXXXXXX
      - MYSQL_USER=XXXXXXXX
  app:
    image: nextcloud
    restart: always
    links:
      - db
    volumes:
      - /root/nextcloud/ncdata:/var/www/html
    environment:
      - MYSQL_PASSWORD=XXXXXXXX
      - MYSQL_DATABASE=XXXXXXXX
      - MYSQL_USER=XXXXXXXX
      - MYSQL_HOST=XXXXXXXX
      - NEXTCLOUD_TRUSTED_DOMAINS=abc.xyz.aa
      - OVERWRITEHOST=abc.xyz.aa:XXXX
      - OVERWRITEPROTOCOL=https
        
  web:
       image: nginx
       restart: always
       ports:
         - 8082:8080
       links:
         - app
       volumes:
         - /root/nextcloud/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
         - /root/nextcloud/cert:/etc/cert
===========
Nginx Configuration file
===========

server {
  listen 80;
  server_name abc.xyz.aa;
  return 301 https://$server_name:8080$request_uri;
  add_header X-Content-Type-Options              "nosniff";
}
server {
  listen 8080 ssl;
  server_name abc.xyz.aa;
  ssl_certificate /etc/cert/abc.xyz.aa.crt;
  ssl_certificate_key /etc/cert/abc.xyz.aa.key;
  ssl_prefer_server_ciphers on;
  location / {
  proxy_pass http://app;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
 }

===========




Kubernetes(k8s) Sample Commands - 02

Following are a few of the  kubectl commands for managing Kubernetes clusters:

  • kubectl get nodes -o=jsonpath='{XX}'
    • This command retrieves information about the nodes in the cluster using the jsonpath output format. Replace {XX} with the desired path.
  • kubectl get nodes -o=custom-columns=<Column name>
    • This command retrieves information about the nodes in the cluster using custom columns output format. Replace <Column name> with the desired column name
  • --sort-by=
    • This option is used to sort the output based on a specified field.
  • kubectl get node node01 -o json > /opt/outputs/node01.json
    • This command retrieves information about a specific node and saves it as a JSON file.
  • kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os.txt
    • This command retrieves the OS image of all the nodes in the cluster and saves it in a text file.
  • kubectl config view --kubeconfig=my-kube-config -o jsonpath="{.users[*].name}" > /opt/outputs/users.txt
    • This command retrieves the names of all users in the kubeconfig file and saves it in a text file.
  • kubectl get pv --sort-by=.spec.capacity.storage > /opt/outputs/storage-capacity-sorted.txt
    • This command retrieves the capacity of all persistent volumes and sorts the output by storage capacity.
  • kubectl config view --kubeconfig=my-kube-config -o jsonpath="{.contexts[?(@.context.user=='aws-user')].name}" > /opt/outputs/aws-context-name
    • This command retrieves the context name for a specific user in the kubeconfig file.
  • kubectl run test-nslookup --image=busybox:1.28 --rm -it --restart=Never -- nslookup nginx-resolver-service
    • This command creates a pod named test-nslookup and runs a DNS lookup on nginx-resolver-service.
  • kubectl run test-nslookup --image=busybox:1.28 --rm -it --restart=Never -- nslookup nginx-resolver-service > /root/CKA/nginx.svc
    • This command creates a pod named test-nslookup and redirects the output of the DNS lookup to a file.
  • K get nodes -o jason | jq -c paths |grep type
    • This command retrieves the paths of all fields in the node objects in the cluster that contain the word "type".
  • kubectl create deployment --image=nginx nginx --replicas=4 --dry-run=client -o yaml > nginx-deployment.yaml
    • This command creates a deployment named nginx with 4 replicas and saves the deployment manifest as a YAML file. The --dry-run=client flag is used to simulate the deployment without actually creating it.

Monday, November 7, 2022

Updated Metallb 0.13.7 Configuration for K8s 1.25

In the new Metallb 0.13.7 configuration for Kubernetes 1.25, there is a new step that needs to be taken before configuring the address pool. You need to enable the ARP (Address Resolution Protocol) to ensure that the load balancer can correctly route traffic between pods.

To enable the ARP, you need to run the following command:

kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl apply -f - -n kube-system

This command fetches the kube-proxy configuration map, updates the "strictARP" option from "false" to "true" and applies the updated map to the kube-system namespace.

Once ARP is enabled, you can apply the new Metallb configuration file by running the following command:

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml
This command fetches the Metallb configuration file and applies it to your cluster.

Next, you need to create an IP address pool that Metallb can use to assign IP addresses to services. To do this, you can create a YAML file with the following contents:

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: first-pool
  namespace: metallb-system
spec:
  addresses:
  - 172.16.2.80-172.16.2.90
This YAML file creates an IP address pool named "first-pool" in the "metallb-system" namespace. The pool has a range of IP addresses between 172.16.2.80 and 172.16.2.90 that Metallb can use to assign to services.

You can apply this YAML file to your cluster using the following command:

kubectl apply -f <filename>.yaml


With these steps, you have successfully configured Metallb 0.13.7 for Kubernetes 1.25 and set up an IP address pool that Metallb can use to assign IP addresses to services. This will help you improve the load balancing capabilities of your Kubernetes cluster and make it more scalable and reliable.

Updation for the below setup
https://www.adminz.in/2022/01/setting-up-metallb-load-balancer-with.html