Posts


Prep work

The example below will use the OpenEBS hostpath storage classes and operators. Installing openebs is described in my kubernetes storage post.

Determine the storageclass name.

 kubectl get storageclasses.storage.k8s.io

As I’m currently testing openebs in microk8s I will use the storage class named openebs-hostpath in the below examples. As a redis cluster handles its own data

If there are any affinity rules that are wanted set the labels now. This example is going to set a label on a node and set the affinity to look for that as a soft (preferredDuringSchedulingIgnoredDuringExecution) target.

kubectl label nodes [NodeName] workertype=database

Install

helm repo add bitnami https://charts.bitnami.com/bitnami

kubectl create namespace redis-demo

helm install redis --set "global.redis.password=HiThere,global.storageClass=openebs-hostpath,redis.nodeAffinityPreset.type=soft,redis.nodeAffinityPreset.key=workertype,redis.nodeAffinityPreset.values[0]=database" bitnami/redis-cluster --namespace redis-demo

kubectl -n redis-demo get pods

If external access is desired it should be set at deployment by setting cluster.externalAccess.enabled to true as part of the above –set command.

cluster.externalAccess.enabled=true

See the redis-cluster chart docs for externalAccess options.

Output

With those commands run there should be some output that looks like the following.

NAME: redis
LAST DEPLOYED: Sat Feb  5 23:08:17 2022
NAMESPACE: redis-demo
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis-cluster
CHART VERSION: 7.2.1
APP VERSION: 6.2.6** Please be patient while the chart is being deployed **

To get your password run:

export REDIS_PASSWORD=$(kubectl get secret --namespace "redis-demo" redis-redis-cluster -o jsonpath="{.data.redis-password}" | base64 --decode)

You have deployed a Redis™ Cluster accessible only from within you Kubernetes Cluster.INFO: The Job to create the cluster will be created. To connect to your Redis™ cluster:

  1. Run a Redis™ pod that you can use as a client:
kubectl run --namespace redis-demo redis-redis-cluster-client --rm --tty -i --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image docker.io/bitnami/redis-cluster:6.2.6-debian-10-r95 -- bash
  1. Connect using the Redis™ CLI:
redis-cli -c -h redis-redis-cluster -a $REDIS_PASSWORD

Remove redis cluster

helm delete redis --namespace redis-demo
kubectl delete namespace redis-demo

Reference


This post is going to cover using a virtual machine to host a vpn client in a virtual machine to secret the connection from the host machine. The example will be using hyper-v, openvpn, Ubuntu 18.04, and gnome network manager.

Why? Why not? Also, in the world of working from home it is nice to keep the host device separate from the work network in the case of bringing your own device.

Anyway, using Ubuntu with ‘network manager’ makes the type of vpn easy to switch. I’m using Ubuntu 18.04 because it has the best default integration with Windows when using hyper-v. The other reason for using Ubuntu is because it is 2gb or less download while a Windows vm is closer to 20gb. I don’t want to download that much or waste that much disk space. I can also run Ubuntu with a low cpu and memory impact as an interface to a remote machine. Hyper-v is being used because that is what I have on my Windows machine at the moment. Feel free to use vmware, virtual box, parallels, kvm, whatever.

This is mostly going to be a visual guide. I am making the assumption everyone knows how to use google or some similar search engine to fill in the blanks.

I’ve included more screenshots than I normally would in case people are not familiar with Ubuntu. Search Ubuntu, it is easy to use. However, I don’t have screenshots for everything and I’ve not annotated the screenshots.

Hyper-v, VM Install

Hyper-v pick an operating system

Hyper v quick create option hyper v quick create menu option

Ubuntu 18.04 has the best integration, at the moment of writing, in hyper-v for linux integration in the quick create options. hyper v quick create vm options

Demonstrate windows download is huge. I advise against choosing windows as the vm. See below and use the ubuntu option (or really whatever you are like). Large windows vm download.

Ubuntu download, much smaller. ubuntu download

Ubuntu downloaded. Connect to the machine to finish the install. Ubuntu downloaded

Ubuntu install

Start ubuntu. If you see any error messages about missing drives or anything press enter or the space bar a couple times. Or do both until it starts (one time setup problem). Start ubuntu

Follow the ubuntu install prompts until you are at the login screen. pick a language

Machine name and credentials

Once the install is done you can pick a screen resolution. I like full screen. The nice thing with ubuntu 18.04 quick create is it comes with hyper-v enhanced sessions enabled so resolution changes apply easily at any time. Pick a screen resolution

If you see an xrdp session login you are running in enhanced mode. Login Ubuntu login

The default ubuntu desktop. You’ll notice you are connected using ‘remote desktop’. The bottom left hand side with 9 circles in a square is the application searcher. You will use it to open applications. The default ubuntu desktop

Open VPN Client

Open a terminal command prompt to install open vpn and import your ovpn file. This is assuming you are using an ovpn file that has the certs inlined. search and open terminal

Update and restart the machine and then log back in.

sudo apt update
sudo apt upgrade
sudo apt reboot

Log back in and install openvpn.

sudo apt install network-manager-openvpn-gnome

With openvpn network manager support added lets import the ovpn file.

sudo nmcli connection import type openvpn file FILE_PATH_NAME

FILE_PATH_NAME is the full path to the .ovpn file if you are not in the same directory.

For example on my machine it might look like this

sudo nmcli connection import type openvpn file /home/peter/downloads/[Whatever-The-File-Is-Named].ovpn

At this point you can enable the vpn in the gui. You’ll want to enter your username and password. Ubuntu will also prompt you for your password and a password for a new keyring.

Install network-manager-openvpn-gnome

network-manager-openvpn-gnome installed

Network Manager GUI options

In the upper right hand of the ubuntu system there will be a network icon that can be clicked to show the network settings including the vpn. From here you can turn on the vpn or modified the credentials to connect.

Modify the vpn to settings to add your credentials

Remote desktop in Ubuntu

Use the Remmina client that is already installed as part of the quick create ubuntu 18.04 vm. It can be found in the application search. If for some reason remmina is not installed it can be installed from the terminal.

sudo apt install remmina

Find and open remmina

Once remmina is open click the green + button to configure a new connection.
Remmina front screen

  1. Give the profile an easy to understand name. Maybe the machine name. Some nice description.
  2. Then enter the server name. You probably will need to use the IP address. I almost always have to use the IP address unless it is a public dns name.
  3. Set the color depth as the default probably will not work from inside the vm. I found true color (24 bpp) worked fine. remmina connection settings

At this point click Save and Connect.

You should at this point be remoted into the remote machine from within the VM that you are running on your local machine. The local machine can use your local internet and not have to worry about the vpn and the vpn does not need to know about your local machine.




This is an update on an older post from 2012.

Connecting to a servicestack (see servicestack.net) service from php is very easy. If you go to https://github.com/majorsilence/WebServiceDotNetTesting there is a c# project that has one service called Hello. This service will listen on http://localhost:9200.

In the php folder there is a script servicestack-php.php that will connect to the c# servicestack web service.

The main functions that can be used are get_data_curl, post_data_curl, put_data_curl. These function can be used with both HTTP, HTTPS, and can connect to open services and services protected with basic authentication.

function get_data_curl($base_url, $service_name, $query_string, $credentials)
{

	
	// Will create a string like "http://localhost:9200/servicestack/json/syncreply/Hello";
	$url = $base_url . '/' . $service_name . '/' . $query_string;
	
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	
	// Override the default headers
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 
		'Accept: application/json', "Expect: 100-continue"));
	
	// 0 do not include header in output, 1 include header in output
	curl_setopt($process, CURLOPT_HEADER, 0);   
	
	// Set username and password
	if ($credentials != "")
	{
		curl_setopt($ch,CURLOPT_USERPWD, $credentials); 
	}
	
	curl_setopt($process, CURLOPT_TIMEOUT, 30); 
	
	// if you are not running with SSL or if you don't have valid SSL
	$verify_peer = false;
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer);
	
	// Disable HOST (the site you are sending request to) SSL Verification,
	// if Host can have certificate which is invalid / expired / not signed by authorized CA.
	$verify_host = false;
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verify_host);
	
	
	// Set so curl_exec returns the result instead of outputting it.
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	
	// Get the response and close the channel.
	$response = curl_exec($ch);
	curl_close($ch);
	
	$json_obj = json_decode($response);
	return $json_obj;
}


function put_data_curl($base_url, $service_name, $post_data, $credentials)
{

	
	// Will create a string like "http://localhost:9200/servicestack/json/syncreply/Hello";
	$url = $base_url . '/json/syncreply/' . $service_name;
	
	
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	
	// Override the default headers
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 
		'Accept: application/json', "Expect: 100-continue"));
	
	// 0 do not include header in output, 1 include header in output
	curl_setopt($process, CURLOPT_HEADER, 0);   
	
	// Set username and password
	if ($credentials != "")
	{
		curl_setopt($ch,CURLOPT_USERPWD, $credentials); 
	}
	
	curl_setopt($process, CURLOPT_TIMEOUT, 30); 
	
	// if you are not running with SSL or if you don't have valid SSL
	$verify_peer = false;
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer);
	
	// Disable HOST (the site you are sending request to) SSL Verification,
	// if Host can have certificate which is invalid / expired / not signed by authorized CA.
	$verify_host = false;
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verify_host);
	
	// Set the post variables
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	
	// Set so curl_exec returns the result instead of outputting it.
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	
	// Get the response and close the channel.
	$response = curl_exec($ch);
	curl_close($ch);
	
	$json_obj = json_decode($response);
	return $json_obj;
}

You can use the function like this.

get_hello_info();
post_hello_info();
put_hello_info();

function get_hello_info()
{
	/*
	$username = "user";
	$password = "password";
	$cred = "{$username}:{$password}";
	*/
	// If you are connecting to a service that uses basic authentication 
	// you can use the code above to set the credentials.
	$cred = "";

	$json = get_data_curl("http://localhost:9200", "Hello", "Testthisservice", $cred);
	echo 'Get Result: ' . $json->{'Result'} . "<br />";
}


function post_hello_info()
{
	$json_str = json_encode(array('Name' =>  'Test this service'));
	
	
	/*
	$username = "user";
	$password = "password";
	$cred = "{$username}:{$password}";
	*/
	// If you are connecting to a service that uses basic authentication 
	// you can use the code above to set the credentials.
	$cred = "";

	$json = post_data_curl("http://localhost:9200", "Hello", $json_str, $cred);
	echo 'Post Result: ' . $json->{'Result'} . "<br />";
}


function put_hello_info()
{
	$json_str = json_encode(array('Name' =>  'Test this service'));
	
	
	/*
	$username = "user";
	$password = "password";
	$cred = "{$username}:{$password}";
	*/
	// If you are connecting to a service that uses basic authentication 
	// you can use the code above to set the credentials.
	$cred = "";

	$json = put_data_curl("http://localhost:9200", "Hello", $json_str, $cred);
	echo 'Put Result: ' . $json->{'Result'} . "<br />";
}