<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cluster Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/tag/cluster/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/tag/cluster/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Thu, 18 Apr 2019 14:21:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.9</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>Cluster Archives - LucD notes</title>
	<link>https://www.lucd.info/tag/cluster/</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>Optimize-VMwarePKS</title>
		<link>https://www.lucd.info/2019/04/03/optimize-vmwarepks/</link>
					<comments>https://www.lucd.info/2019/04/03/optimize-vmwarepks/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Wed, 03 Apr 2019 19:29:51 +0000</pubDate>
				<category><![CDATA[DRS]]></category>
		<category><![CDATA[Folder]]></category>
		<category><![CDATA[PKS]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Optimise]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=6336</guid>

					<description><![CDATA[A guest post Over the last couple of weeks, it has been my [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">A guest post</h3>



<p>Over the last couple of weeks, it has been my great pleasure to assist  <a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://twitter.com/chipzoller" target="_blank">Chip Zoller</a> in writing a <a rel="noreferrer noopener" aria-label="VMware PowerCLI (opens in a new tab)" href="https://communities.vmware.com/community/vmtn/automationtools/powercli" target="_blank">VMware PowerCLI</a> script, named <a rel="noreferrer noopener" aria-label="Optimize-VMwarePKS (opens in a new tab)" href="https://github.com/chipzoller/Optimize-VMwarePKS" target="_blank">Optimize-VMwarePKS</a>. This script helps organise your PKS deployment at three levels: folders, tags and DRS rules, including functionality to run a clean up.</p>



<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="858" height="546" src="https://www.lucd.info/wp-content/uploads/2019/03/pks-pcli.png" alt="" class="wp-image-6337" srcset="https://www.lucd.info/wp-content/uploads/2019/03/pks-pcli.png 858w, https://www.lucd.info/wp-content/uploads/2019/03/pks-pcli-300x191.png 300w, https://www.lucd.info/wp-content/uploads/2019/03/pks-pcli-768x489.png 768w, https://www.lucd.info/wp-content/uploads/2019/03/pks-pcli-720x458.png 720w" sizes="(max-width: 858px) 100vw, 858px" /><figcaption>VMware PKS</figcaption></figure>



<p>The following post by Chip describes the function in greater detail, and shows how you can use it. </p>



<p>This post also appears on the <strong>Sovereign Systems</strong> website as <a rel="noreferrer noopener" aria-label="Optimize-VMwarePKS: A PowerShell Script for All Your VMware PKS Deployment Needs (opens in a new tab)" href="https://www.sovsystems.com/optimize-vmwarepks-a-powershell-script-for-all-your-vmware-pks-deployment-needs/" target="_blank">Optimize-VMwarePKS: A PowerShell Script for All Your VMware PKS Deployment Needs</a>.</p>



<p>Take it away Chip.</p>



<span id="more-6336"></span>



<h2 class="wp-block-heading">Optimize-VMwarePKS: A
PowerShell script for all your VMware PKS deployment needs</h2>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ever since
VMware PKS (now called Enterprise PKS) came onto the market over a year ago,
it’s been a big hit. With it, you get upstream Kubernetes, NSX-T, an enterprise-class
container registry, automation of the entire K8s cluster creation process, and
lots more all on top of the de facto private cloud platform of vSphere. It’s
truly becoming the way organizations are standardizing on K8s cluster
instantiation, upgrade, and management on-premises. The deployment nodes
themselves are regular virtual machines. And, like all virtual machines, you
and your company probably have an established way of organizing those VMs.
While Enterprise PKS takes care of a lot of tasks automatically, one thing that
we still need to consider is how those VMs get organized. So, as a joint effort
between myself and <a href="https://twitter.com/LucD22">Luc Dekens</a>, we’re
glad to announce today a new script called <strong>Optimize-VMwarePKS</strong>
which is designed to bring that level of optimization to your vSphere and PKS
clusters. Specifically, this script is designed to optimize your PKS
deployments in three ways: vSphere folders, vSphere tags, and DRS rules–with
clean-up for three of these. Read on to see this in action and learn how you
can greatly simplify deployment of PKS clusters in your own environment.</p>



<h3 class="wp-block-heading"><strong>FOLDERS</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </h3>



<p>As mentioned, PKS deploys K8s nodes
as simple VMs into your vSphere environment. After a single deployment, you may
see something like this in your vSphere Client.</p>



<figure class="wp-block-image"><img decoding="async" width="317" height="165" src="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_16-35-40.png" alt="" class="wp-image-6338" srcset="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_16-35-40.png 317w, https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_16-35-40-300x156.png 300w" sizes="(max-width: 317px) 100vw, 317px" /></figure>



<p>All VMs are, as you can see, named with IDs that are doled
out by PKS and BOSH, and tracked internally. They probably look very different
from the internal naming standard you’ve developed, right? Although we shouldn’t
change the names of the VMs, we can do other things. The first feature of <strong>Optimize-VMwarePKS</strong> is the ability to place
all VMs from a given deployment automatically into a folder based on that name.
In so doing, the above screenshot now looks like this after optimization:</p>



<figure class="wp-block-image"><img decoding="async" width="367" height="311" src="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_16-59-11.png" alt="" class="wp-image-6339" srcset="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_16-59-11.png 367w, https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_16-59-11-300x254.png 300w" sizes="(max-width: 367px) 100vw, 367px" /></figure>



<p>As you can see, these folder names align with the PKS
cluster names perfectly if we examine them with a pks clusters
command. In fact, <strong>Optimize-VMwarePKS</strong>
is designed to take this information directly from the PKS CLI tool, which is a
requirement for the script (see later).</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="658" height="86" src="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-00-30.png" alt="" class="wp-image-6340" srcset="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-00-30.png 658w, https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-00-30-300x39.png 300w" sizes="auto, (max-width: 658px) 100vw, 658px" /></figure>



<p>The nice thing about this script is </p>



<ol class="wp-block-list"><li>it’s very easy to operate (simply add the –ProcessFolders switch)</li><li>it’s idempotent so will keep this organization
no matter how many times you run it.</li></ol>



<h3 class="wp-block-heading"><strong>TAGS</strong></h3>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The second
feature of <strong>Optimize-VMwarePKS</strong> to highlight
is the ability to assign vSphere Tags to all of the VMs that form a given PKS
deployment. Tags are often used to provide a form of organization that may
exist alongside or independent of vSphere folders. These tags are, again by
default, created based on the name of the PKS cluster and automatically created
and assigned to all VMs part of a cluster. With a tag category of your choice
(or by accepting the default category of ‘PKS’), the script will detect your
clusters, create a new appropriate tag in the tag category, and assign that tag
to all VMs.</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="187" height="232" src="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-11-01.png" alt="" class="wp-image-6341"/></figure>



<p>As you can see here, the script has created two tags for us
that match the names of our clusters. If we inspect the VMs within those
clusters, we can see it’s been correctly assigned as well.</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="689" height="278" src="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-12-03.png" alt="" class="wp-image-6342" srcset="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-12-03.png 689w, https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-12-03-300x121.png 300w" sizes="auto, (max-width: 689px) 100vw, 689px" /></figure>



<p>This optimization is easily enabled with the -ProcessTags switch.</p>



<h3 class="wp-block-heading"><strong>DRS RULES</strong></h3>



<p>            Since PKS has the ability to deploy HA K8s clusters–which is a tremendous strength and huge time saver–it automatically provisions multiple masters and places them behind an NSX-T load balancer. These masters then serve as the API entry point for all K8s-related commands. Masters can be spread out across multiple Availability Zones (AZ). Where AZs map directly onto distinct vSphere clusters, this provides a sufficient level of fault isolation. But in the case where either multiple Azs aren’t in use or they do not align to separate compute clusters, Enterprise PKS will place all masters on the same cluster. Optimize-VMwarePKS can therefore be used to build DRS anti-affinity rules to provide such separation.</p>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In my
previous screenshots, you’ve noticed I have a single small cluster (1 master; 3
workers) and a large cluster (3 masters; 3 workers). If we run the script with
the -ProcessDRSRules switch, it will
automatically find those masters and create a DRS anti-affinity rule for us.
And not to worry, it’ll only create the rule with the masters of each cluster,
so multiple HA clusters get individual DRS rules created. See below. Even
better, the script is written in a future-proof way in that when VMware/Pivotal
support larger multi-master clusters in the future, if you scaled out masters
the script will detect the increase and update the rule for you!</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="527" height="592" src="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-19-04.png" alt="" class="wp-image-6343" srcset="https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-19-04.png 527w, https://www.lucd.info/wp-content/uploads/2019/03/2019-03-24_17-19-04-267x300.png 267w" sizes="auto, (max-width: 527px) 100vw, 527px" /></figure>



<p>These abilities are, as I hope you’ll agree, extremely
useful in order to not only fill some gaps but bring VMware PKS deployments
into alignment with your vSphere policies today. But there’s one thing missing
that we haven’t covered yet. Kubernetes clusters may come and go (another big
win for Enterprise PKS is the automatic roll-back of NSX-T objects!), and when
they do we want to ensure we aren’t leaving behind elements that are no longer
relevant. So the last portion of <strong>Optimize-VMwarePKS</strong>
is its ability to automatically maintain a tidy house.</p>



<h3 class="wp-block-heading"><strong>TIDYING UP</strong></h3>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Each of the
three optimizations shown previously (folders, tags, and DRS rules) can be
switched on independently. And with each one, except DRS rules, if a cluster
gets deleted we’d have some clean-up work to do. So the script has also been
written with switches that you can (optionally, of course) automate the
clean-up of these objects. We’re talking here about tidying up of vSphere
folders and vSphere tags. By adding the -TidyFolders
and/or -TidyTags switches, <strong>Optimize-VMwarePKS</strong> will search for these empty folders and tags and
remove them for you. But, not to fear, it will *only* do this if you’ve
provided these switches and also only consider the parent vSphere folder or tag
category for clean-up. That means it won’t scour your entire estate and remove
anything else.</p>



<h3 class="wp-block-heading"><strong>IDEMPOTENCE</strong></h3>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lastly, and
before we look at some running examples, is to point out the idempotent nature
of this script. Because you may have many groups of people bring up and down
PKS deployments, you need something that can maintain a ready state of what you
define, similar to tools like Ansible, Puppet, and Chef. Being able to schedule
this script is one of the main reasons it was written, and in so doing it must
be made idempotent. No matter how many times you run the script, it always
checks if things exist before making a change. You can be confident that when
you ask it to run with whatever parameters that it’ll maintain that state
exactly. So no fear if someone drops a tag or moves a VM out of a folder. Next
time it runs it’ll put it right back where it was.</p>



<h3 class="wp-block-heading"><strong>RUNNING
OPTIMIZE-VMWAREPKS</strong></h3>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Now you’re
aware of all its capabilities, let’s quickly look at what’s needed to run it
and then an example on how to run it.</p>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The script
needs PowerShell, <a href="https://www.powershellgallery.com/packages/VMware.PowerCLI/">VMware PowerCLI</a>,
and the <a href="https://network.pivotal.io/products/pivotal-container-service">PKS
CLI binary tool</a>, all of which are cross-platform at this point. In fact, it
has been tested running directly from the Pivotal Operations Manager appliance
running Ubuntu with <a href="https://github.com/PowerShell/PowerShell">PowerShell
Core</a> but runs perfectly fine from a Windows control machine as well. The
PKS CLI tool needs to be added to your PATH. You also must ensure you have
credentials and network connectivity to access both vCenter Server and PKS.</p>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Now you
have the prereqs, time to actually run this script. Grab it from the <a href="https://github.com/chipzoller/Optimize-VMwarePKS">GitHub repo here</a>. For
your convenience (and so you don’t have to either read a blog or inspect the
code), extensive help has been provided on how to operate the script, its
parameters, but some examples.</p>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; All the
switches can be run independently, so you can mix and match whatever
functionality you like and only it will run. If we want to let it process
folders, tags, and DRS rules for us, we could call it like so:</p>



<pre class="wp-block-code"><code>$secvCPass = ConvertTo-SecureString -String 'VMware1!' -asPlainText -Force
$credvC = New-Object System.Management.Automation.PSCredential('administrator@vsphere.local',$secvCPass)
$secPKSPass = ConvertTo-SecureString -String 'VMware1!' -asPlainText -Force
$credPKS = New-Object System.Management.Automation.PSCredential('myuser',$secPKSPass)

./Optimize-VMwarePKS.ps1 -ProcessFolders -ProcessTags -ProcessDRSRules -vCenter $vc -vCenterCredential $credvC -PKSSever $pks -PKSCredential $credPKS -Verbose</code></pre>



<p>We have to pass a PSCredential object to the script, and so
the lines before actually running it do that for us.</p>



<p>If all you wanted was to clean-up (tidy) those objects, run
it with only those flags set:</p>



<pre class="wp-block-code"><code>./Optimize-VMwarePKS.ps1 -TidyFolders -TidyTags -vCenter $vc -vCenterCredential $credvC -PKSSever $pks -PKSCredential $credPKS</code></pre>



<p>Or, combine all flags into a single command:</p>



<pre class="wp-block-code"><code>./Optimize-VMwarePKS.ps1 -ProcessFolders -ProcessTags -ProcessDRSRules -TidyFolders -TidyTags -vCenter $vc -vCenterCredential $credvC -PKSSever $pks -PKSCredential $credPKS</code></pre>



<p>As far as managing the parameters needed, one of the most
convenient ways is with <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-6">splatting</a>
in PowerShell. We can write a script, call it “wrapper.ps1” and put all
parameters inside of it as shown below. Note that with splatting, we must set
the values to “true” unlike when passing the switches to the script directly. The
final line simply calls <strong>Optimize-VMwarePKS</strong>
for us passing the entire splat as an argument.</p>



<pre class="wp-block-code"><code>$vCUser = 'myuser@mydomain.com'
$vCPass = 'VMware1!' | ConvertTo-SecureString -asPlainText -Force
$PKSUser = 'myuser'
$PKSPass = 'VMware1!' | ConvertTo-SecureString -asPlainText -Force

$params = @{
ProcessFolders = $true
ProcessTags = $true
ProcessDRSRules = $true
TidyFolders = $true
TidyTags = $true
vCenter = 'myvcenter.mydomain.com'
PKSServer = 'mypks.mydomain.com'
vCenterCredential = New-Object System.Management.Automation.PSCredential($vCUser,$vCPass)
PKSCredential = New-Object System.Management.Automation.PSCredential($PKSUser,$PKSPass)
}

/home/ubuntu/Optimize-VMwarePKS.ps1 @params</code></pre>



<p>And, as mentioned earlier, because this script is entirely
idempotent, it can easily be scheduled with either cron, Windows task
scheduler, or any other mechanism you want. This will ensure your environment
is kept optimized based on your rules and patterns with no manual clean-up
required.</p>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I hope you find this script to be valuable in your environments. If so, we’d love to hear about it and you can drop either Luc or Chip a line on Twitter at <a href="https://twitter.com/LucD22" target="_blank" rel="noreferrer noopener" aria-label="@LucD22 (opens in a new tab)">@LucD22</a> or <a rel="noreferrer noopener" aria-label="@chipzoller (opens in a new tab)" href="https://twitter.com/chipzoller" target="_blank">@chipzoller</a> respectively.</p>



<hr class="wp-block-separator"/>



<p>Thanks Chip.<br></p>



<p>Enjoy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2019/04/03/optimize-vmwarepks/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
