Skip to content

Instantly share code, notes, and snippets.

@welshstew
Last active May 16, 2022 11:47
Show Gist options
  • Save welshstew/9125d7e17ed87dbff81017ebb9309831 to your computer and use it in GitHub Desktop.
Save welshstew/9125d7e17ed87dbff81017ebb9309831 to your computer and use it in GitHub Desktop.

Deploy and investigate app deployment on Windows Node

oc get nodes -l kubernetes.io/os=windows
oc new-project windows-workloads
oc create -f https://gist.githubusercontent.com/welshstew/9125d7e17ed87dbff81017ebb9309831/raw/4d522e5bf6cadd8a6b1ae9f71319c7ddc20fcbaf/win-webserver.yaml
oc get pods -n windows-workloads -o wide
oc get deploy win-webserver -n windows-workloads -o jsonpath='{.spec.template.spec.tolerations}' | jq -r

oc -n openshift-windows-machine-config-operator rsh deploy/winc-ssh
sshcmd.sh ${IP_ADDRESS}

PS C:\Users\Administrator> docker images
PS C:\Users\Administrator> Get-Process | ?{ $_.ProcessName -match "kube|overlay|docker" } 
PS C:\Users\Administrator> docker ps
PS C:\Users\Administrator> exit

oc expose svc/win-webserver -n windows-workloads
curl -s http://$(oc get route win-webserver -n windows-workloads -o jsonpath='{.spec.host}')
oc -n windows-workloads exec -it deploy/win-webserver -- powershell
PS C:\> tasklist /M /FI "IMAGENAME eq powershell.exe"  | Select-String -Pattern http
PS C:\Users\Administrator> exit

Scale windows nodes

oc get machinesets -n openshift-machine-api | grep windows
oc get machines -n openshift-machine-api  -l machine.openshift.io/os-id=Windows
oc describe node ${NODE} | grep -i Taint
oc scale machineset ${MACHINESET} --replicas=2 -n openshift-machine-api
oc logs deploy/windows-machine-config-operator -n openshift-windows-machine-config-operator -f
oc scale machineset ${MACHINESET} --replicas=1 -n openshift-machine-api
oc get events -n openshift-machine-api 

Check Operator

oc get OperatorGroup -n openshift-windows-machine-config-operator 
oc get Subscription -n openshift-windows-machine-config-operator 
oc get csv -n openshift-windows-machine-config-operator

NetCandy Store .net Core app + MSSQL DB running on linux nodes talking to .NET Windows app running on Windows Server Node

Note: Once you've verified you are a cluster admin, you can extract the following information. You will need the hostname of the Windows node installed and the ssh-key used to login to the Windows Node. The reason for this is part of the Helm Chart deploys a Job that downloads the image of the frontend application as a pre-deploy task.

helm version
chmod go-r /home/ec2-user/.kube/config
$ export WSSHKEY=$(oc get secret cloud-private-key -n openshift-windows-machine-config-operator -o jsonpath='{.data.private-key\.pem}')
$ export WNODE=$(oc get nodes -l kubernetes.io/os=windows -o jsonpath='{.items[0].metadata.name}')
helm repo add redhat-demos https://redhat-developer-demos.github.io/helm-repo
helm repo update
helm install ncs --namespace netcandystore \
--create-namespace --timeout=1200s \
redhat-demos/netcandystore \
--set ssh.hostkey=${WSSHKEY} --set ssh.hostname=${WNODE}

Explore deployment

oc get pods -n netcandystore -l app=netcandystore -o wide
oc get nodes -l kubernetes.io/os=windows
oc get pods -n netcandystore -l app=getcategories -o wide
oc get route netcandystore -n netcandystore -o jsonpath='{.spec.host}{"\n"}'
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
labels:
machine.openshift.io/cluster-api-cluster: "cluster-6c9s5-64b6q"
name: "cluster-6c9s5-64b6q-windows-eu-central-1a"
namespace: openshift-machine-api
spec:
replicas: 1
selector:
matchLabels:
machine.openshift.io/cluster-api-cluster: "cluster-6c9s5-64b6q"
machine.openshift.io/cluster-api-machineset: "cluster-6c9s5-64b6q-worker-eu-central-1a"
template:
metadata:
labels:
machine.openshift.io/cluster-api-cluster: "cluster-6c9s5-64b6q"
machine.openshift.io/cluster-api-machine-role: worker
machine.openshift.io/cluster-api-machine-type: worker
machine.openshift.io/cluster-api-machineset: "cluster-6c9s5-64b6q-worker-eu-central-1a"
machine.openshift.io/os-id: Windows
spec:
metadata:
labels:
node-role.kubernetes.io/worker: ""
providerSpec:
value:
ami:
id: "ami-0752f5e0425af9419"
apiVersion: awsproviderconfig.openshift.io/v1beta1
blockDevices:
- ebs:
iops: 0
volumeSize: 120
volumeType: gp2
credentialsSecret:
name: aws-cloud-credentials
deviceIndex: 0
iamInstanceProfile:
id: "cluster-6c9s5-64b6q-worker-profile"
instanceType: m5a.4xlarge
kind: AWSMachineProviderConfig
placement:
availabilityZone: "eu-central-1a"
region: "eu-central-1"
securityGroups:
- filters:
- name: tag:Name
values:
- "cluster-6c9s5-64b6q-worker-sg"
subnet:
filters:
- name: tag:Name
values:
- "cluster-6c9s5-64b6q-private-eu-central-1a"
tags:
- name: "kubernetes.io/cluster/cluster-6c9s5-64b6q"
value: owned
userDataSecret:
name: windows-user-data
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: win-webserver
name: win-webserver
spec:
selector:
matchLabels:
app: win-webserver
replicas: 1
template:
metadata:
labels:
app: win-webserver
name: win-webserver
spec:
tolerations:
- key: "os"
value: "Windows"
Effect: "NoSchedule"
containers:
- name: windowswebserver
image: mcr.microsoft.com/windows/servercore:ltsc2019
imagePullPolicy: IfNotPresent
command:
- powershell.exe
- -command
- $listener = New-Object System.Net.HttpListener; Get-PSDrive; $listener.Prefixes.Add('http://*:80/'); $listener.Start();New-Item -Path C:\Data -Name hello2.txt;Write-Host('Listening at http://*:80/'); while ($listener.IsListening) { $context = $listener.GetContext(); $response = $context.Response; $content='<html><body><H1>Windows Container Web Server</H1></body></html>'; $buffer = [System.Text.Encoding]::UTF8.GetBytes($content); $response.ContentLength64 = $buffer.Length; $response.OutputStream.Write($buffer, 0, $buffer.Length); $response.Close(); };
volumeMounts:
- mountPath: "C:\\Data"
name: volume
volumes:
- name: volume
emptyDir: {}
nodeSelector:
beta.kubernetes.io/os: windows
apiVersion: v1
kind: Service
metadata:
name: win-webserver
labels:
app: win-webserver
spec:
ports:
# the port that this service should serve on
- port: 80
targetPort: 80
selector:
app: win-webserver
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: win-webserver
name: win-webserver
spec:
selector:
matchLabels:
app: win-webserver
replicas: 1
template:
metadata:
labels:
app: win-webserver
name: win-webserver
spec:
tolerations:
- key: "os"
value: "Windows"
Effect: "NoSchedule"
containers:
- name: windowswebserver
image: mcr.microsoft.com/windows/servercore:ltsc2019
imagePullPolicy: IfNotPresent
command:
- powershell.exe
- -command
- $listener = New-Object System.Net.HttpListener; $listener.Prefixes.Add('http://*:80/'); $listener.Start();Write-Host('Listening at http://*:80/'); while ($listener.IsListening) { $context = $listener.GetContext(); $response = $context.Response; $content='<html><body><H1>Windows Container Web Server</H1></body></html>'; $buffer = [System.Text.Encoding]::UTF8.GetBytes($content); $response.ContentLength64 = $buffer.Length; $response.OutputStream.Write($buffer, 0, $buffer.Length); $response.Close(); };
nodeSelector:
beta.kubernetes.io/os: windows
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: winc-ssh
name: winc-ssh
namespace: openshift-windows-machine-config-operator
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: winc-ssh
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: winc-ssh
spec:
containers:
- command:
- /bin/bash
- -c
- |
sleep infinity
image: quay.io/redhatworkshops/winc-ssh:latest
imagePullPolicy: Always
name: winc-ssh-container
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /tmp/ssh
name: sshkey
readOnly: true
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: sshkey
secret:
defaultMode: 256
secretName: cloud-private-key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment