Install openIDL Node on AWS
Prerequisites
Wiki Markup |
---|
\{
"Version": "2012-10-17",
"Statement": \[
\{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": \[
"sns:*",
"cloudformation:ListStacks",
"application-autoscaling:*",
"s3:*",
"logs:*",
"cloudtrail:*",
"dynamodb:*",
"sts:*",
"elasticloadbalancing:*",
"autoscaling:*",
"iam:*",
"route53domains:*",
"secretsmanager:*",
"cloudwatch:*",
"ses:*",
"kms:*",
"route53:*",
"lambda:*",
"ec2:*",
"cognito-idp:*",
"ebs:*",
"eks:*",
"acm:*",
"rds:*"
\],
"Resource": "*"
\}
\]
\} |
...
AWS Account
...
- The user should have access to IAM and permissions to create a new users and roles. The user will be only used to create a Terraform user and role with the following policy contents.
Terraform Cloud Account
Preconfigured access in
~/.terraformrc
. Get the token from https://app.terraform.io by going to Settings → Teams → Team API Token. Generate a new token and create the file~/.terraformrc
Code Block credentials "app.terraform.io" { token = "iz5o8MNxgBBPwQ...." }
# | Step | |
---|---|---|
1 | Setup |
|
...
|
...
|
...
|
...
|
...
|
...
Procedure
The terraform/terragrunt scripts in openid-devops Git repository are used to create the required IAM roles and users, and the Kubernetes cluster that will host Jenkins and Ansible Tower. The modules' backend is configured to use Terraform Cloud.
Terragrunt executes the scripts via the preconfigured backend. The backend is configured to run Terraform from Terraform Cloud (Execution mode: remote) so the AWS credentials have to be set under the workspace's variables as Environment variables:
The backend (Terraform Cloud workspace) is created and initialized by Terragrunt automatically
...
| ||
2 | Create IAM User & Role |
|
...
|
...
export AWS_ACCESS_KEY_ID="ASIAWRO3..."
export AWS_SECRET_ACCESS_KEY="6gLd..."
export AWS_SESSION_TOKEN="IQoJpZ2l..."
|
...
The script creates:
|
...
| |
3 | Create |
...
Ops Kubernetes Cluster |
|
...
|
...
|
...
|
...
|
...
|
...
The script creates:
| ||
4 | Import the Kubernetes Cluster connection config | Make sure you have an AWS |
...
profile set in your ~/
Find the name of the Kubernetes cluster and update the local config with it
| ||||||||||||
5 | Install |
...
Nginx |
|
...
| ||||
6 | Install Jenkins | Use the helm chart for installing Jenkins onto the Kubernetes cluster created above.
|
...
|
...
|
...
Wait for Jenkins to start up. To view the Jenkins admin password:
|
...
Set up a cloud-provisioned Jenkins node as defined in the Kubernetes plugin config in Jenkins. | ||||||
7 | Install Ansible Tower (AWX) | Create the AWX DB by connecting to the RDS PostgreSQL instance created via Terraform.
|
...
|
...
|
...
Install AWX with the Kustomize |
...
command.
|
...
Watch for the script failing and if it does run it again (timing issue due to the creation of the AWX RBAC) | ||
8 | Update DNS record (optional) |
|
...
|
...
Now Jenkins and AWX should be available via |
...
...
...
and |
...
...
Terraform Cloud Workspaces
We need to maintain two workspaces - one for the Fabric Kubernetes cluster and one for the openIDL applications.
To create the workspaces use the tool located in {+}https://bitbucket.org/senofi/openidl-devops/src/develop/+:
- Go to openidl-devops/aws-infrastructure/environments/<env-folder>/terraform-cloud and run
terragrunt plan
If everything looks ok, execute terragrunt apply. This should create two workspaces and a var set in Terraform Cloud.
- Create a new KMS key (symetric, encrypt/decrypt) in the AWS console. The name is not important but use a meaningful name that will associate it with this environment. Use it to populate the property in the next step
- Go to openidl-devops/automation/terraform-cloud and update configuration.properties Make sure that the varset name
- Create SSH keys
ssh-keygen -t rsa -f app_eks_worker_nodes_ssh_key.pem
ssh-keygen -t rsa -f blk_eks_worker_nodes_ssh_key.pem
ssh-keygen -t rsa -f bastion_ssh_key.pem
- Populate the variable set by executing the following command in openidl-devops/automation/terraform-cloud
pip install -r requirements.txt
python populate-variable-set.py
- Copy the contents of the public keys and populate them in Terraform Cloud UI under Variable Sets → <the newly created varset>
Configure Jenkins
- Set Jenkins node label 'openidl' in Kubernetes Cloud by going to Manage Jenkins → Manage Nodes and Clouds → Configure Clouds. Make sure that under Pod Template details the labels field contains the value 'openidl'.
Also, remove the prepopulated 'sleep' command if it is set on the pod template:
- Create the Terraform Job Template
- Terraform Token Secret - Login to Jenkins go to Manage Jenkins → Manage Credentials → Stores scoped to Jenkins (Jenkins) → Global Credentials (unrestricted) → Add credentials
Choose Kind as secret text, enter secret text like Token in "secret" field and name the secret ID as unique since it will be used in pipeline code.
- Git Credentials - Add a new credential
- Terraform Job
- Go to Jenkins → New Item. Use a name such as Terraform Job
- Select job type as PIPELINE and proceed.
- Select Definition as Pipeline Script from SCM
- Select SCM as Git
- Key in the Infrastructure code repository (openidl-gitops) URL.
- Select the Git credential created above
- Specify the relevant branch "refs/heads/<branch-name>".
- Set script path to jenkins-jobs/jenkinsfile-tf
Run Terraform Job
- Run the Jenkins Terraform Job
- Open the console log for the job. Once the job asks for an input accept and choose the apply option
- The job runs a second plan into the Kubernetes workspace in Terraform Cloud. When asked - accept and apply the changes
- Go to the AWS Console and find EKS (Elastic Kubernetes Service). Choose the blk cluster and go to Add-Ons. Find the EBS plugin and add it to the list. The plugin makes sure volumes could be created in Kubernetes
Application Deployment
Application TLS Cert
- Deploy cert manager using helm , include CRD deployment as part of the helm install command (Note 1.11.0 doesn't work on k8s 1.20) - {+}https://cert-manager.io/docs/installation/helm/+
- Deploy an issuer (kubectl apply)
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
email: openidl@senofi.ca
privateKeySecretRef:
name: letsencrypt-prod
server: https://acme-v02.api.letsencrypt.org/directory
solvers:
...