Skip to content

Updated the apiVersion of resources #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
56 changes: 28 additions & 28 deletions workshop-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ metadata:
user: "${namespace}"
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: role-${namespace}
namespace: ${namespace}
Expand Down Expand Up @@ -46,7 +46,7 @@ rules:
- list
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: rb-${namespace}
namespace: ${namespace}
Expand All @@ -62,7 +62,7 @@ roleRef:
name: role-${namespace}
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: rb-def-${namespace}
namespace: ${namespace}
Expand All @@ -71,7 +71,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: default
namespace: ${mamespace}
namespace: ${namespace}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand All @@ -96,16 +96,16 @@ namespace() {
: ${workshopNamespace:? required}

kubectl create ns ${namespace}
kubectl label ns ${namespace} user=${namespace}
kubectl label ns ${namespace} user=${namespace}
assign-role-to-ns ${namespace} | kubectl create -f -

kubectl create clusterrolebinding crb-${namespace} --clusterrole=lister --serviceaccount=${workshopNamespace}:sa-${namespace}
kubectl label clusterrolebinding crb-${namespace} user=${namespace}
kubectl label clusterrolebinding crb-${namespace} user=${namespace}
kubectl create clusterrolebinding crb-cc-${namespace} --clusterrole=common-config --serviceaccount=${workshopNamespace}:sa-${namespace}
kubectl label clusterrolebinding crb-cc-${namespace} user=${namespace}
kubectl label clusterrolebinding crb-cc-${namespace} user=${namespace}

kubectl create clusterrolebinding crb-ssh-${namespace} --clusterrole=sshreader --serviceaccount=${workshopNamespace}:sa-${namespace}
kubectl label clusterrolebinding crb-ssh-${namespace} user=${namespace}
kubectl label clusterrolebinding crb-ssh-${namespace} user=${namespace}
}

enable-namespaces() {
Expand All @@ -116,7 +116,7 @@ enable-namespaces() {
kubectl config set-context $(kubectl config current-context) --namespace=default
kubectl apply -f https://raw.githubusercontent.com/lalyos/k8s-ns-admission/master/deploy-webhook-job.yaml
kubectl config set-context $(kubectl config current-context) --namespace=${origns}
fi
fi
kubectl patch clusterrole lister --patch='{"rules":[{"apiGroups":[""],"resources":["nodes","namespaces"],"verbs":["*"]}]}'
}

Expand All @@ -130,11 +130,11 @@ depl() {
: ${namespace:? required}
: ${gitrepo:? required}
: ${sessionSecret:=cloudnative1337}

local name=${namespace}

cat <<EOF
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
Expand Down Expand Up @@ -169,7 +169,7 @@ spec:
- name: NS
value: ${name}
- name: TILLER_NAMESPACE
value: ${name}
value: ${name}
- name: NODE
valueFrom:
fieldRef:
Expand All @@ -184,7 +184,7 @@ spec:
name: dev
volumeMounts:
- mountPath: /root/workshop
name: gitrepo
name: gitrepo
---
apiVersion: v1
kind: Service
Expand All @@ -202,14 +202,14 @@ spec:
run: ${name}
type: NodePort
---
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.org/websocket-services: ${name}
labels:
user: "${namespace}"
name: ${name}
name: ${name}
spec:
rules:
- host: ${name}.${domain}
Expand All @@ -225,18 +225,18 @@ dev() {
declare namespace=${1}
: ${namespace:? required}
: ${workshopNamespace:? required}

namespace ${namespace}
namespace ${namespace}play
kubectl create rolebinding crb-${namespace}-x \
--role=role-${namespace}play \
--namespace=${namespace}play \
--serviceaccount=${workshopNamespace}:sa-${namespace}

depl ${namespace}| kubectl create -f -
depl ${namespace}| kubectl create -f -

wait-for-deployment ${namespace}
get-url ${namespace}
get-url ${namespace}
}

presenter() {
Expand All @@ -253,7 +253,7 @@ presenter-url() {
kubectl expose deployment user0 --port 8888 --type=NodePort --name presenter
fi

externalip=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type == "ExternalIP")].address}')
externalip=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type == "ExternalIP")].address}')
kubectl get svc presenter -o jsonpath="open http://${externalip}:{.spec.ports[0].nodePort}"
echo
}
Expand All @@ -265,8 +265,8 @@ get-url() {

sessionUrl=http://${deployment}.${domain}/
kubectl annotate deployments ${deployment} --overwrite sessionurl="${sessionUrl}"
externalip=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type == "ExternalIP")].address}')

externalip=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type == "ExternalIP")].address}')
nodePort=$(kubectl get svc ${deployment} -o jsonpath="{.spec.ports[0].nodePort}")
sessionUrlNodePort="http://${externalip}:${nodePort}${rndPath}"
kubectl annotate deployments ${deployment} --overwrite sessionurlnp=${sessionUrlNodePort}
Expand Down Expand Up @@ -360,15 +360,15 @@ workshop-context() {
return
fi
kubectl config view --minify --flatten > config-orig.yaml
kubectl create ns ${workshopNamespace}
cp config-orig.yaml config-workshop.yaml
kubectl create ns ${workshopNamespace}
cp config-orig.yaml config-workshop.yaml
export KUBECONFIG=$PWD/config-workshop.yaml
kubectl config set-context $(kubectl config current-context) --namespace=${workshopNamespace}
echo "---> context set to use namespace: ${workshopNamespace}, by:"
echo "export KUBECONFIG=$KUBECONFIG"
}

clean-user() {
clean-user() {
ns=$1;
: ${ns:?required};

Expand Down Expand Up @@ -405,16 +405,16 @@ EOF
# https://kubernetes.github.io/ingress-nginx/deploy/#gce-gke
echo "---> create: ns,cm,sa,crole,dep"
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.26.1/deploy/static/mandatory.yaml
echo "---> creates single LB"
echo "---> creates single LB"
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.26.1/deploy/static/provider/cloud-generic.yaml
fi

ingressip=$(kubectl get svc -n ingress-nginx ingress-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')

echo "---> checking DNS A record (*.${domain}) points to: $ingressip ..."
if [[ $(dig +short "*.${domain}") == $ingressip ]] ; then
echo "---> checking DNS A record (*.${domain}) points to: $ingressip ..."
if [[ $(dig +short "*.${domain}") == $ingressip ]] ; then
echo "DNS setting are ok"
else
else
echo "---> set external dns A record (*.${domain}) to: $ingressip"
fi
}
Expand Down