The virtual machine host ( trial two )
Candidate for a course for 60 minutes >> CODE >>> reach express and help the audience who struggles with this
Objective : Create a virtual machine to configure a kubernetes cluster
Key Result: Do it in a infrastructure as Code
Key Results: Manage in Azure with Orchestrators Create and Operate
Key Result: Delete and recreate to save the costs
Key Result : Use GPT to do your setup for the syntax
Key Result : Connect to a Linux box which is Kubernetes container friendly
Key Result : Install local xrdp to connect from the local to the cloud
Key Result : Document in a way you can share share
Key Result : learn budgetting in Azure and cost of the resources.
Key Result : Learn to use ssh from local and cloud shell
Key Result : first principles approach test script and add it to the iac
Key Result : OKR and first principles concepts
Key Result : Learning journey with Lacan and Bloom Concepts
Resource Groups > 2
one creater
one is the main

+


Starting Empty



Security group

virtual machine with the ip

Connect with SSH



network settings

one bash script and shell to run it

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install xrdp
sudo ufw allow 3389/tcp
echo "gnome-session" > ~/.xsession
sudo systemctl restart xrdp
move to bash


better naming

Save commands for

check it out


check it to run it

ask gpt for the command
The error message "Permission denied" indicates that your current user does not have the necessary permissions to execute the script setxrdp.sh. To resolve this issue, you can try the following steps:
- Check the script permissions: You can use the
ls -lcommand to view the current permissions of the file:
ls -l setxrdp.sh
This will show you the permissions currently set for the file. Look for the execute permission (x) in the output.
- Make the script executable: If the execute permission is not set for the script, you can add it using the
chmodcommand. This command modifies the file permissions. To make the script executable for the user who owns it, you can run:
chmod u+x setxrdp.sh
This command sets the execute (x) permission for the user (u) who owns the file. If you want to make it executable for all users, replace u+x with a+x.
- Execute the script with elevated permissions: If the script needs to perform operations that require higher privileges, you might need to run it with
sudo(assuming you have sudo privileges):
sudo ./setxrdp.sh
Using sudo executes the script with superuser (administrator) privileges, which may be necessary for tasks like modifying system configurations or installing software.
Try these steps and see if you can execute the script successfully. If you still face issues, there may be other factors at play, such as the script's content or specific system security configurations.
now it starts


why silent runs are important

sudo apt-get update -y``sudo apt-get upgrade -ysudo apt-get install xrdp -y
sudo ufw allow 3389/tcp``echo "gnome-session" > ~/.xsession``sudo systemctl restart xrdp
added -y to the parts that i can

matrix going on as the packages are getting install > get your coffee > check for the networking > network chucks channel great videos

Wrong security group lets check it

Check the last commands

End goal after integrating add it to iac script
Add key results

restart the box

Ask gpt for the error but first connect and fail




add 8080


you need add all to test for the first time

different popup

I can see it gets connected but a black screen
Semblance > Lacan >>> most give up IT due to connection issues

ask gpt and follow the steps

A black screen issue when connecting to a Linux system using RDP and xRDP can stem from various reasons. Here are some troubleshooting steps to help resolve the problem:
- Check xRDP Service Status: Ensure that the xRDP service is running on your Linux machine. You can check this by running:
sudo systemctl status xrdp
If the service isn't running, start it with:
sudo systemctl start xrdp
- Verify Desktop Environment Compatibility: xRDP might not work correctly with certain desktop environments. For example, GNOME with Wayland might pose problems. If you are using Ubuntu with GNOME, try installing a different desktop environment that is known to work better with xRDP, such as XFCE:
sudo apt install xfce4
After installing, you'll need to configure xRDP to use XFCE:
echo "startxfce4" > ~/.xsession
Restart the xRDP service:
sudo systemctl restart xrdp
- Update
.xsessionFile: Ensure your.xsessionfile in your home directory is configured to start the correct desktop session. You can set this file to start the desktop environment you are using. For example, for XFCE, you would use:
echo xfce4-session > ~/.xsession
-
Adjust RDP Client Settings: Sometimes, settings on the RDP client on your Mac might cause display issues. Check if changing the display settings (such as color depth or resolution) in your RDP client resolves the issue.
-
Review xRDP Logs: Look at the xRDP logs for any errors or warnings that might give you more insight into what's going wrong. You can find the logs here:
sudo cat /var/log/xrdp.log
sudo cat /var/log/xrdp-sesman.log
-
Ensure Proper Network Configuration: Verify that there are no network issues preventing proper communication between your Mac and the Linux server. This includes checking firewalls and network policies.
-
Reinstall xRDP: If all else fails, you might consider uninstalling and then reinstalling xRDP:
sudo apt remove xrdp
sudo apt install xrdp
By following these steps, you should be able to resolve the black screen issue with xRDP on your Linux system. If problems persist, it might be useful to look for specific issues related to the Linux distribution and version you are using, as there might be known issues with certain setups.]]
running it showed

opened up

than volla

now all blue >>> desktop software not loaded to linux

ask gpt and install it

To install a Linux desktop environment on Ubuntu 18.04 for your user interface (UI) usage, you have several options, depending on what kind of experience you're looking for. Below are instructions for installing three popular desktop environments: GNOME, KDE Plasma, and XFCE.
GNOME (Default Desktop for Ubuntu 18.04)
Ubuntu 18.04 comes with GNOME by default. If for some reason GNOME is not installed, or you've removed it and want to reinstall it, you can do so using the following commands:
sudo apt update
sudo apt install ubuntu-desktop
This command installs the full GNOME desktop environment along with the standard Ubuntu applications and optimizations.
KDE Plasma
KDE Plasma is known for its visual appeal and customization options. It offers a more feature-rich and configurable desktop experience. To install KDE Plasma:
sudo apt update
sudo apt install kubuntu-desktop
When you install kubuntu-desktop, you'll be prompted to choose between sddm and lightdm as your display manager. sddm is the default for KDE, and choosing it would typically provide a smoother experience with KDE Plasma.
XFCE
XFCE is a lightweight desktop environment that is fast and uses fewer system resources, making it ideal for older hardware or for users who seek a simple, efficient, and highly customizable desktop environment. To install XFCE:
sudo apt update
sudo apt install xubuntu-desktop
After Installation
After installing any of these desktop environments:
-
Log Out or Reboot: You can either log out or reboot your machine. When you get to the login screen, you might see an option to select your desktop environment.
-
Switch Desktop Environments: If you have multiple desktop environments installed, you can switch between them at the login screen. Look for a session or environment menu on the login screen (usually a small gear icon next to the login button) and select the desktop environment you wish to use.
-
Configure Your Environment: Each desktop environment has its own settings manager where you can customize the appearance and behavior of your desktop, like themes, keyboard shortcuts, and more.
Choose the desktop environment that best suits your needs based on the performance of your system and your personal preferences in terms of usability and appearance.
Install using the ssh

reconnect with saved creadential from mac and windows

first principles the desktop opened up

update your script with the minus y
sudo apt-get update -y
sudo apt-get upgrade -ysudo apt-get install xrdp -y
sudo ufw allow 3389/tcp
echo "gnome-session" > ~/.xsession
sudo install ubuntudesktop -ysudo systemctl restart xrdp
Setup the compute

Check basic apps like youtube

Check cpu and gpu usage

now delete and redo it
missing > the sh file correct network security group
ask gpt and give the script as well ( stop point >>> 1 hour course )

take it from the center > help gpt

get a hold of content size > dont forget we live infinite computing

shows me the place to update

2 of them


getting set at the bottom

update and save

incremental > just update the deployment name to be able to see it

Run the trigger

+
error in workflow

double mention

^^^
Promote an older version


todo > student prerequisities ( 1 hour ) / setup azure
wrong place to update and not updated auto saves

now saved

remove 2 and run

green man is here

incremental deployment much faster

^^^
check config

check the diff > the first principle
rdp rule is in reconnect


ping basic public dns

save the code
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Create_or_update_a_template_deployment": {
"inputs": {
"body": {
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"defaultValue": "rifaterdemsahin",
"metadata": {
"description": "Specifies a username for the Virtual Machine."
},
"type": "string"
},
"location": {
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specifies the location for all resources."
},
"type": "string"
},
"projectName": {
"defaultValue": "oshost",
"metadata": {
"description": "Specifies a name for generating resource names."
},
"type": "string"
},
"vmSize": {
"defaultValue": "Standard_D2s_v3",
"metadata": {
"description": "description"
},
"type": "string"
}
},
"resources": [
{
"apiVersion": "2020-05-01",
"location": "[parameters('location')]",
"name": "[variables('networkSecurityGroupName')]",
"properties": {
"securityRules": [
{
"name": "ssh_rule",
"properties": {
"access": "Allow",
"description": "Locks inbound down to ssh default port 22.",
"destinationAddressPrefix": "*",
"destinationPortRange": "22",
"direction": "Inbound",
"priority": 123,
"protocol": "Tcp",
"sourceAddressPrefix": "*",
"sourcePortRange": "*"
}
},
{
"name": "RDP_rule",
"properties": {
"access": "Allow",
"description": "Allow RDP access through port 3389.",
"destinationAddressPrefix": "*",
"destinationPortRange": "3389",
"direction": "Inbound",
"priority": 124,
"protocol": "Tcp",
"sourceAddressPrefix": "*",
"sourcePortRange": "*"
}
}
]
},
"type": "Microsoft.Network/networkSecurityGroups"
},
{
"apiVersion": "2020-05-01",
"location": "[parameters('location')]",
"name": "[variables('publicIPAddressName')]",
"properties": {
"publicIPAllocationMethod": "Dynamic"
},
"sku": {
"name": "Basic"
},
"type": "Microsoft.Network/publicIPAddresses"
},
{
"apiVersion": "2020-05-01",
"comments": "Simple Network Security Group for subnet [variables('vNetSubnetName')]",
"location": "[parameters('location')]",
"name": "[variables('networkSecurityGroupName2')]",
"properties": {
"securityRules": [
{
"name": "default-allow-22",
"properties": {
"access": "Allow",
"destinationAddressPrefix": "*",
"destinationPortRange": "22",
"direction": "Inbound",
"priority": 1000,
"protocol": "Tcp",
"sourceAddressPrefix": "*",
"sourcePortRange": "*"
}
}
]
},
"type": "Microsoft.Network/networkSecurityGroups"
},
{
"apiVersion": "2020-05-01",
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName2'))]"
],
"location": "[parameters('location')]",
"name": "[variables('vNetName')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('vNetAddressPrefixes')]"
]
},
"subnets": [
{
"name": "[variables('vNetSubnetName')]",
"properties": {
"addressPrefix": "[variables('vNetSubnetAddressPrefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
}
]
},
"type": "Microsoft.Network/virtualNetworks"
},
{
"apiVersion": "2020-05-01",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('vNetName'))]",
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
],
"location": "[parameters('location')]",
"name": "[variables('networkInterfaceName')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('vNetSubnetName'))]"
}
}
}
]
},
"type": "Microsoft.Network/networkInterfaces"
},
{
"apiVersion": "2021-11-01",
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
],
"location": "[parameters('location')]",
"name": "[variables('vmName')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
}
]
},
"osProfile": {
"adminPassword": "@{parameters('vmpassword')}",
"adminUsername": "[parameters('adminUsername')]",
"computerName": "[variables('vmName')]",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "18_04-lts-gen2",
"version": "latest"
},
"osDisk": {
"createOption": "fromImage"
}
}
},
"type": "Microsoft.Compute/virtualMachines"
}
],
"variables": {
"networkInterfaceName": "[concat(parameters('projectName'), '-nic')]",
"networkSecurityGroupName": "[concat(parameters('projectName'), '-nsg')]",
"networkSecurityGroupName2": "[concat(variables('vNetSubnetName'), '-nsg')]",
"publicIPAddressName": "[concat(parameters('projectName'), '-ip')]",
"vNetAddressPrefixes": "10.0.0.0/16",
"vNetName": "[concat(parameters('projectName'), '-vnet')]",
"vNetSubnetAddressPrefix": "10.0.0.0/24",
"vNetSubnetName": "default",
"vmName": "[concat(parameters('projectName'), '-vm')]"
}
}
}
},
"host": {
"connection": {
"name": "@parameters('$connections')['arm']['connectionId']"
}
},
"method": "put",
"path": "/subscriptions/@{encodeURIComponent('2cb217c1-366d-41c0-8934-3f82869320d8')}/resourcegroups/@{encodeURIComponent('Openshift')}/providers/Microsoft.Resources/deployments/@{encodeURIComponent('linuxhost2')}",
"queries": {
"wait": false,
"x-ms-api-version": "2016-06-01"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
},
"vmpassword": {
"defaultValue": "YYmm123!YYmm123!",
"type": "String"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"arm": {
"connectionId": "/subscriptions/2cb217c1-366d-41c0-8934-3f82869320d8/resourceGroups/OpenshiftHelper/providers/Microsoft.Web/connections/arm",
"connectionName": "arm",
"id": "/subscriptions/2cb217c1-366d-41c0-8934-3f82869320d8/providers/Microsoft.Web/locations/uksouth/managedApis/arm"
}
}
}
}
}

now make sure the sh automation is added > use incremental for practical checks
Get ideas

To add a shell script that runs during the VM creation in Azure using your provided Logic Apps-based VM deployment template, you'll want to include the shell script in the ARM template section that defines the virtual machine configuration. This is typically done using the customScriptExtension which allows you to execute scripts on the VM after it's been provisioned.
Here’s a step-by-step guide on how to modify your existing template to include a shell script for installing packages:
-
Define the Custom Script Extension in the ARM Template: You will add a new resource to the ARM template that uses the
Microsoft.Compute/virtualMachines/extensionstype. This extension will run your shell script. -
Add Your Script: You'll need the script available either in a publicly accessible location (like a GitHub gist or a storage account) or you can directly encode it in the ARM template if it's not too long.
Here's an example of how you might configure the customScriptExtension:
{
"type": "extensions",
"name": "customScriptExtension",
"apiVersion": "2021-11-01",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.1",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["
},
"protectedSettings": {
"commandToExecute": "bash
}
}
}
-
Add the Extension to Your ARM Template:
-
Place the above JSON block into the
resourcesarray of the VM definition in your ARM template. Ensure that you replace<URL_to_your_script>and<name_of_your_script.sh>with actual values. -
The
"dependsOn"section should correctly reference the VM resource to ensure that the script runs after the VM is provisioned. -
Update Any Necessary Parameters and Variables: Make sure that any new parameters or variables you introduce (like URLs or script names) are defined in the parameters or variables section of the template.
-
Deploy the Updated Template: Once the ARM template is updated, deploy it through the same mechanism you usually would (e.g., through the Azure portal, using Azure CLI, or directly from Logic Apps).
If your shell script is intended to configure the VM further or install specific packages, ensure that it contains all the necessary commands to do so and that it's tested in a local or staging environment before being applied to production VMs.
By following these steps, you should be able to integrate a shell script for installing packages into your Azure VM provisioning process using Azure Logic Apps and ARM templates.
Get key part and add it to the helper resource group

Favorites > Storage


Goal keep the helper resource group cost as low as possible
Linux container

download as text and change the extension


upload and get the link

SAS URL genereate


https://scritpts.blob.core.windows.net/linux/xrdpsetup.sh?sp=r&st=2024-04-14T10:56:09Z&se=2029-04-14T18:56:09Z&spr=https&sv=2022-11-02&sr=b&sig=eIBoiRyT4m0xUJCHI%2BdZbGKcqzNfn7VUHXIDpxifESc%3D
ask gpt to add it

{
"type": "extensions",
"name": "customScriptExtension",
"apiVersion": "2021-11-01",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.1",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"https://scritpts.blob.core.windows.net/linux/xrdpsetup.sh?sp=r&st=2024-04-14T10:56:09Z&se=2029-04-14T18:56:09Z&spr=https&sv=2022-11-02&sr=b&sig=eIBoiRyT4m0xUJCHI%2BdZbGKcqzNfn7VUHXIDpxifESc%3D"
]
},
"protectedSettings": {
"commandToExecute": "bash xrdpsetup.sh"
}
}
}
URL for the sh> https://docs.google.com/document/d/1AzbSs5pvMs7MZUDctIH3r-o_Ha_XBs68MfhCeAhUvQI/edit?usp=sharing
Easier to add to the top with the comma

make it thelinuxhost4withscript more understandtable
and run leave breadcrumbs

vm name can be wrong the depends on


as it is on the top easier to find > and update [concat(parameters('projectName'), '-vm')]
update

name in multiple places

add new version

syntax error

ask gpt > not one error multiple errors

save and rerun

see the green

check incremental deployments

now destroy manually dont wait 3 days
you can always rename better by cloning

renamed

createresourcegroup to deletecreateresourcegroup
remove the old one
Get better at symbols every time

Breadcrumbs for yourself

Deletion takes time > get coffee and you can not connect

Cleaned up

Rerun > this can be also createupdate host

Coming in

Check the new ip

52.151.91.57
edit in remote desktop

initial connection makes you wait as the system needs to reboot
add reboot at the end
add to sh file make it richer

edit script with what you learned

^^^Save it

GPT improve the script and read it

Much richer and more to learn

Before copy paste

Read with gpt



Added logging that we desperately wanted

Manual restart is there

Check activity log for cloud logs

Black screen problem is back > the desktop might not be installed
firewall and xrdp is there but not ui

Go to zero point and retry and now you know the code gets triggered

have detailed logs > after deletion it would be much harder

unique resources takes longer time to delete and can get locked! >> shared infra and names!

Refresh would show them going out

update this


not that fast

use gpt


generic and auto update

Green light check seconds and colors

Better naming coming on

more transactional customextensions is taking a longer time

Let it finish and time it

8minutes


Add a library becomes another task
update the operating system is another task

Thanks for joining the training hope the pain of creating a linux vm in the cloud with automation and connecting with the ui is solved. Meet you in the next exercise.
Moving to express it

References >
^^^
https://rifaterdemsahin.com/2024/04/09/openshift-is-back
Imported from rifaterdemsahin.com · 2024