- Stop dreaming, start doing!
- Stop overthinking , start doing !
- stop starting start finishing (Agile Thinking)
- Life is really simple, but we insist on making it complicated.
- Keep calm and carry on.
- Everything falls all the time
- Great until they are not great
- It is not that we have a short space of time, but that we waste much of it.
Quotes
How to Execute Multiple Commands Using a Single sudo
sudo sh -c 'cmd1; cmd2'
The semicolon (;) serves as a special character, enabling us to segregate multiple commands within a single line. sudo sh -c 'cmd1 & cmd2'
K3s on MacBook M1 with multipass
Setting Up a Kubernetes Cluster with Multipass and K3s
In this tutorial, we will walk through the process of setting up a lightweight Kubernetes cluster using Multipass and K3s. Multipass is a tool that allows you to create and manage virtual machines on your local machine, and K3s is a lightweight Kubernetes distribution that is designed for resource-constrained environments. This combination makes it easy to create a local Kubernetes playground for development and testing purposes.
Prerequisites
Before you begin, make sure you have the following prerequisites installed on your machine:
- Homebrew : A package manager for macOS.
Installation
To get started, open your terminal and execute the following commands to install Multipass using Homebrew:
brew install --cask multipass
Creating the Kubernetes Master Node
Let’s start by creating the Kubernetes master node using Multipass. Run the following commands to launch the VM and set its resources:
multipass launch --name k3s --mem 4G --disk 10G
After the VM is launched, access its shell using:
multipass shell k3s
Inside the VM’s shell, run the following commands to install K3s:
curl -sfL https://get.k3s.io | sh -
Retrieve the Kubernetes token and the VM’s IP address:
mytoken=$(multipass exec k3s sudo cat /var/lib/rancher/k3s/server/node-token)
myip=$(multipass info k3s | grep -i ip | tr -d ' ') ; myip=${myip/IPv4:/} ; echo $myip
Creating Worker Nodes
Next, let’s create two Kubernetes worker nodes named k3s-w1 and k3s-w2 with the following commands:
multipass launch --name k3s-w1 --mem 2G --disk 10G
multipass launch --name k3s-w2 --mem 2G --disk 10G
Run the following commands to install K3s on the worker nodes:
multipass exec k3s-w1 -- bash -c "curl -sfL https://get.k3s.io | K3S_URL=https://$myip:6443 K3S_TOKEN=$mytoken sh -"
multipass exec k3s-w2 -- bash -c "curl -sfL https://get.k3s.io | K3S_URL=https://$myip:6443 K3S_TOKEN=$mytoken sh -"
Verifying the Cluster
Now that the cluster is set up, let’s verify it by checking the nodes:
multipass exec k3s -- bash -c "sudo kubectl get nodes"
Cleanup
After you’ve finished working with the Kubernetes cluster, you can delete the VMs using the following commands:
multipass delete k3s k3s-w1 k3s-w2
multipass purge
Conclusion
In this tutorial, we’ve learned how to set up a Kubernetes cluster using Multipass and K3s. This lightweight setup is ideal for local development and testing purposes. It allows you to experiment with Kubernetes concepts without the need for a cloud-based environment. Remember that this setup is not suitable for production environments, but it’s a great tool for learning and exploration.
Remove Rancher
git clone https://github.com/rancher/rancher-cleanup.git
cd rancher-cleanup/
kubectl create -f deploy/rancher-cleanup.yaml
kubectl -n kube-system logs -l job-name=cleanup-job -f
kubectl -n cattle-system get pods | grep ^rancher | head -n 1 | awk '{ print $1 }'
kubectl create -f deploy/verify.yaml
kubectl -n kube-system logs -l job-name=verify-job -f
kubectl -n kube-system logs -l job-name=verify-job -f | grep -v "is deprecated"
kubectl get namespace
Installing Rancher on Azure Kubernetes Service
brew update && brew install azure-cli && brew install helm
az login
az group create --name rancher02-rg --location eastus
az aks get-versions --location eastus --output table
az aks create --resource-group rancher02-rg --name rancher-server --kubernetes-version 1.19.13 --node-count 1 --node-vm-size Standard_D2_v3
az aks get-credentials --resource-group rancher02-rg --name rancher-server
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm upgrade --install \
ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx \
--set controller.service.type=LoadBalancer \
--version 3.12.0 \
--create-namespace
kubectl get service ingress-nginx-controller --namespace=ingress-nginx
https://rancher42.eastus.cloudapp.azure.com
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
kubectl create namespace cattle-system
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.5.1/cert-manager.crds.yaml
#kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.1.0/cert-manager.yaml
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.5.1
kubectl get pods --namespace cert-manager
# we use letsEncrypt
# OK:
helm install rancher rancher-stable/rancher \
--namespace cattle-system \
--set hostname=rancher42.eastus.cloudapp.azure.com \
--set replicas=1 \
--set ingress.tls.source=letsEncrypt \
--set letsEncrypt.email=mail@gmail.com
kubectl -n cattle-system rollout status deploy/rancher
kubectl -n cattle-system describe pod
kubectl -n cattle-system get pods
kubectl -n cattle-system logs -f rancher-784d94f59b-vgqzh
curl -v rancher42.eastus.cloudapp.azure.com
Docker Commands
System information
docker version
docker info
Pull images
Login to the docker hub repository
List images
Remove images
doceker rmiRun Container
Run Detached Mode
List Containers
Stop Container
Start Container
docker start <container>
Restart Container
docker restart <container>
Remove Containers
Exec Bash
Checking History
Low-level information
Copy Files
Own Docker Images
List Service
Update Service
List Stack
Remove Stack
Deploy Stack
Using MkDocs with git on Windows and Linux
MkDocs is static site generator.
Windows
choco install pythonchoco install pip
set https_proxy=http://localhost:3128
pip install --upgrade pip --userpip install mkdocs
Linux
Kubernetes command
# Rancher
kubectl get -n cattle-system pods
kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{"\n"}}'
kubectl -n cattle-system logs -f $(kubectl -n cattle-system get pods | grep ^rancher | head -n 1 | awk '{ print $1 }')
kubectl delete namespace cattle-system
# Pods
kubectl get pods --show-labels
kubectl describe pod -l app=app1
kubectl exec deploy/app1 -- hostname
kubectl exec deploy/app1 -- killall5
kubectl get pods
kubectl delete pods -l app=app1
# Deployment
kubectl apply -f file.yaml
kubectl apply -f web/
# Services
kubectl get svc
kubectl get pods -l app=web
kubectl logs -l app=web
kubectl get svc web
# Execute
kubectl exec deploy/app1 -- nslookup web
kubectl exec deploy/app1 -- curl http://web:8080
# Output
kubectl get svc bb-web -o jsonpath='{}'
kubectl get svc bb-web -o jsonpath='http://{.status.loadBalancer.ingress[0].*}:8080'
# Endpoint
kubectl get endpoints
kubectl get all -l demo=workshop1
kubectl delete all -l demo=workshop1
# ConfigMap
kubectl get configmaps -A
kubectl describe configmap ample -n ns
# Container Deployment
kubectl run http --image=docker-http-server:latest --replicas=1
kubectl get deployments
kubectl describe deployment http
kubectl expose deployment http --external-ip="172.17.0.29" --port=8000 --target-port=80
kubectl get svc
# Replication Controller
kubectl create -f redis-master-controller.yaml
kubectl get rc
kubectl get pods
Install Elasticsearch + Kibana ( ELK) on Windows
choco install nssm
curl https://artifacts.elastic.co/downloads/kibana/kibana-7.6.2-windows-x86_64.zip -o kibana-7.6.2-windows-x86_64.zip
7z x kibana-7.6.2-windows-x86_64.zip -oc:/elastic
nssm install kibana C:\elastic\kibana-7.6.2-windows-x86_64\bin\kibana.bat
sc start kibana
curl http://localhost:5601
How to verify checksum on a Mac - SHA1, SHA256
SHA1 checksum
shasum -a 1 fileSHA256 checksum
shasum -a 256 fileInstalling Grafana on Windows
install
choco install grafanaConfig
copy c:\ProgramData\chocolatey\lib\grafana\tools\grafana-6.3.6\conf\defaults.ini c:\ProgramData\chocolatey\lib\grafana\tools\grafana-6.3.6\conf\custom.ini"C:\Program Files\Notepad++\notepad++.exe" c:\ProgramData\chocolatey\lib\grafana\tools\grafana-6.3.6\conf\custom.ini
http_port = 8080
Windows Service
choco install nssmnssm install grafana c:\ProgramData\chocolatey\lib\grafana\tools\grafana-6.3.6\bin\grafana-server.exe
sc start grafana
Config Grafana
Configuration - Data Source - name : telegraf - url: http://localhost:8086
Dashboard - Import - https://grafana.com/grafana/dashboards/1902
Install Telegraf
choco install telegraf"C:\Program Files\Notepad++\notepad++.exe" C:\Program Files\telegraf\telegraf.conf
url: http://localhost:8086
database: telegraf
sc start telegraf
Installing InfluxDB on Windows
install
choco install influxdb"C:\Program Files\Notepad++\notepad++.exe" C:\influxdata\influxdb-1.7.10-1\influxdb.conf
Storage
dir = "C:/influxdata/storage/meta"
dir = "C:/influxdata/storage/data"
wal-dir = "C:/influxdata/storage/wal"
logging
logging-enabled = trueHTTP endpoint
[http]Windows Service
choco install nssmnssm install influxdb c:\influxdata\influxdb-1.7.10-1\influxd.exe "-config c:\influxdata\influxdb-1.7.10-1\influxdb.conf"
sc start influxdb
Installing JMeter on Windows with Influxdb and Grafana
install
choco install jmeterConfig JMeter
download:https://github.com/NovatecConsulting/JMeter-InfluxDB-Writer/releases/download/v-1.2/JMeter-InfluxDB-Writer-plugin-1.2.jarcopy to: c:\ProgramData\chocolatey\lib\jmeter\tools\apache-jmeter-5.2.1\lib\ext\
Config InfluxDB
c:\influxdata\influxdb-1.7.10-1/influx.exeCREATE DATABASE jmeter
SHOW DATABASES
Config Grafana
Ansible
Adhoc
Lookup
ansible -m debug localhost -a msg="{{ lookup('url', 'http://localhost:8090/nslookup?host=blog.hilandco.com') }}"Docker shell2http nslookup
Dockerfile
FROM shell2http:bind-tools
RUN apk --no-cache add bind-tools
docker-compose.yml
version: '2'
services:
nslookup_api:
image: shell2http:bind-tools
ports:
- "8090:8080"
restart: unless-stopped
command: [ "-form", "/nslookup", "nslookup -q=A $$v_host | tail -2 | head -1 | awk '{print $$2\" \" $$3\" \" $$4}'" ]
enable hyper-v on windows 2109
Enable-WindowsOptionalFeature –Online -FeatureName Microsoft-Hyper-V –All -NoRestart
Install-WindowsFeature RSAT-Hyper-V-Tools -IncludeAllSubFeature
Install-WindowsFeature RSAT-Clustering -IncludeAllSubFeature
Install-WindowsFeature Multipath-IO
Restart-Computer
Install AWX
mkdir ansible
cd ansible/
export http_proxy=http://<proxy>:3128
export https_proxy=http://<proxy>:3128
export HTTP_PROXY=http://<proxy>:3128
export HTTPS_PROXY=http://<proxy>:3128
git clone https://github.com/ansible/awx.git
cd awx/installer/
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y ansible
yum install -y python-pip python-devel gcc
pip install --upgrade pip
pip uninstall docker docker-py docker-compose
pip install docker-compose
ansible-playbook -i inventory install.yml
URL
http://<awx_server>/#/homeRest API Call
http://<awx_server>/api/v2/job_templates/33/launch/
Launching from Job Templates via the API follows the following workflow:
GET https://your.tower.server/api/v2/job_templates/<your job template id>/launch/
