diff --git a/first_boot.sh b/first_boot.sh index 6b1b338..ba73ef6 100755 --- a/first_boot.sh +++ b/first_boot.sh @@ -32,6 +32,19 @@ #Define Admin user and Password #http POST http://localhost:9000/api/users/admin/init Username="portainer" Password="portainer1234" +#Add the portainer user to the docker group +#usermod -aG docker portainer && newgrp docker + +#Start minikube +#sudo -u portainer minikube start --nodes 2 --driver=none + +#Add the metrics server to the minikube cluster +#sudo -u portainer minikube addons enable metrics-server + +#Add Portainer Agent to the local kind Kubernetes cluster +# curl -L https://downloads.portainer.io/portainer-agent-k8s-nodeport.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml +#sleep 15 + #Get the admin JWT token #http POST :9000/api/auth Username="portainer" Password="portainer1234" #jwt=`http POST :9000/api/auth Username="portainer" Password="portainer1234" | jq '.jwt' | sed 's/^.//' | sed 's/.$//'` @@ -41,20 +54,7 @@ #"Authorization: Bearer $jwt" \ #Name="docker" EndpointCreationType=1 -#Add the portainer user to the docker group -usermod -aG docker portainer && newgrp docker - -#Start minikube -sudo -u portainer minikube start - -#Add the metrics server to the minikube cluster -sudo -u portainer minikube addons enable metrics-server - -#Add Portainer Agent to the local kind Kubernetes cluster -# curl -L https://downloads.portainer.io/portainer-agent-k8s-nodeport.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml -#sleep 30 - #Add local Kubernetes endpoint -#http --form POST :9000/api/endpoints \ -#"Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJwb3J0YWluZXIiLCJyb2xlIjoxLCJleHAiOjE2MjU2MzUxNzB9.RF6-DxP_HAdRwkpi3fPTr7YPjzTBsaioi9Au3njY0YI" \ -#Name="kubernetes" URL="tcp://10.0.2.8:9001" EndpointCreationType=2 +#sudo -u portainer http --form POST :9000/api/endpoints \ +#"Authorization: Bearer $jwt" \ +#Name="kubernetes" URL="tcp://10.0.2.8:30778" EndpointCreationType=2 TLS="true" TLSSkipVerify="true" TLSSkipClientVerify="true" diff --git a/portainer-agent-k8s.yaml b/portainer-agent-k8s.yaml new file mode 100644 index 0000000..146e455 --- /dev/null +++ b/portainer-agent-k8s.yaml @@ -0,0 +1,81 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: portainer +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: portainer-sa-clusteradmin + namespace: portainer +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: portainer-crb-clusteradmin +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: +- kind: ServiceAccount + name: portainer-sa-clusteradmin + namespace: portainer +--- +apiVersion: v1 +kind: Service +metadata: + name: portainer-agent + namespace: portainer +spec: + type: NodePort + selector: + app: portainer-agent + ports: + - name: http + protocol: TCP + port: 9001 + targetPort: 9001 + nodePort: 30778 +--- +apiVersion: v1 +kind: Service +metadata: + name: portainer-agent-headless + namespace: portainer +spec: + clusterIP: None + selector: + app: portainer-agent +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: portainer-agent + namespace: portainer +spec: + selector: + matchLabels: + app: portainer-agent + template: + metadata: + labels: + app: portainer-agent + spec: + serviceAccountName: portainer-sa-clusteradmin + containers: + - name: portainer-agent + image: portainer/agent:latest + imagePullPolicy: Always + env: + - name: LOG_LEVEL + value: DEBUG + - name: AGENT_CLUSTER_ADDR + value: "portainer-agent-headless" + - name: KUBERNETES_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + ports: + - containerPort: 9001 + protocol: TCP