Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit e3d1bd6

Browse files
author
Tanton
committed
- Renamed k8s resources to reflect new project name
- Renamed all resources to "example-*" for consistency - Modified readme so that the step by step getting started is a little easier to follow - Added example gif Signed-off-by: Alexander Tanton <[email protected]>
1 parent 0067efc commit e3d1bd6

10 files changed

+98
-99
lines changed

aws-service-operator-example.gif

2.41 MB
Loading

configs/aws-operator.yaml configs/aws-service-operator.yaml

+19-23
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ items:
44
- kind: Namespace
55
apiVersion: v1
66
metadata:
7-
name: aws-operator
7+
name: aws-service-operator
88

99
- kind: ClusterRole
1010
apiVersion: rbac.authorization.k8s.io/v1beta1
1111
metadata:
12-
name: aws-operator
12+
name: aws-service-operator
1313
rules:
1414
- apiGroups:
1515
- ""
@@ -56,47 +56,43 @@ items:
5656
- kind: ServiceAccount
5757
apiVersion: v1
5858
metadata:
59-
name: aws-operator
60-
namespace: aws-operator
59+
name: aws-service-operator
60+
namespace: aws-service-operator
6161

6262
- kind: ClusterRoleBinding
6363
apiVersion: rbac.authorization.k8s.io/v1beta1
6464
metadata:
65-
name: aws-operator
65+
name: aws-service-operator
6666
roleRef:
6767
apiGroup: rbac.authorization.k8s.io
6868
kind: ClusterRole
69-
name: aws-operator
69+
name: aws-service-operator
7070
subjects:
7171
- kind: ServiceAccount
72-
name: aws-operator
73-
namespace: aws-operator
72+
name: aws-service-operator
73+
namespace: aws-service-operator
7474

7575
- kind: Deployment
7676
apiVersion: apps/v1beta1
7777
metadata:
78-
name: aws-operator
79-
namespace: aws-operator
78+
name: aws-service-operator
79+
namespace: aws-service-operator
8080
spec:
8181
replicas: 1
8282
template:
8383
metadata:
84+
annotations:
85+
iam.amazonaws.com/role: arn:aws:iam::<ACCOUNT_ID>:role/aws-service-operator
8486
labels:
85-
app: aws-operator
87+
app: aws-service-operator
8688
spec:
87-
serviceAccountName: aws-operator
89+
serviceAccountName: aws-service-operator
8890
containers:
89-
- name: aws-operator
90-
image: christopherhein/test-operator:v0.0.1-alpha4
91+
- name: aws-service-operator
92+
image: awsserviceoperator/aws-service-operator:v0.0.1-alpha4
9193
imagePullPolicy: Always
92-
env:
93-
- name: AWS_ACCESS_KEY_ID
94-
value:
95-
- name: AWS_SECRET_ACCESS_KEY
96-
value:
9794
args:
9895
- server
99-
- --cluster-name=<cluster-name>
100-
- --region=<region>
101-
- --bucket=<bucket-name>
102-
- --account-id=<account-id>
96+
- --cluster-name=<CLUSTER_NAME>
97+
- --region=<REGION>
98+
- --account-id=<ACCOUNT_ID>

examples/dynamodb.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: operator.aws/v1alpha1
22
kind: DynamoDB
33
metadata:
4-
name: dynamodb-table
4+
name: example-table-name
55
spec:
66
hashAttribute:
77
name: user_id

examples/ecrrepository.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
apiVersion: operator.aws/v1alpha1
22
kind: ECRRepository
33
metadata:
4-
name: aws-operator-codegen
4+
name: example-repository-name

examples/s3bucket.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: operator.aws/v1alpha1
22
kind: S3Bucket
33
metadata:
4-
name: s3bucket.aws-operator.com
4+
name: Private
55
spec:
66
versioning: true
77
accessControl: PublicRead

examples/snssqssub.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
apiVersion: operator.aws/v1alpha1
33
kind: SNSTopic
44
metadata:
5-
name: chrishein-sns-topic-3
5+
name: example-sns-topic
66

77
---
88
apiVersion: operator.aws/v1alpha1
99
kind: SQSQueue
1010
metadata:
11-
name: chrishein-test-sqs-3
11+
name: example-sqs-queue-name
1212
spec:
1313
contentBasedDeduplication: true
1414
delaySeconds: 5
@@ -21,8 +21,8 @@ spec:
2121
apiVersion: operator.aws/v1alpha1
2222
kind: SNSSubscription
2323
metadata:
24-
name: chrishein-sns-subscription-3
24+
name: example-subscription-name
2525
spec:
26-
topicName: chrishein-sns-topic-3
26+
topicName: example-sns-topic
2727
protocol: sqs
28-
endpoint: chrishein-test-sqs-3
28+
endpoint: example-sqs-queue-name

examples/snssubscription.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apiVersion: operator.aws/v1alpha1
22
kind: SNSSubscription
33
metadata:
4-
name: chrishein-sns-subscription-2
4+
name: example-sns-subscription-name
55
spec:
6-
topicName: chrishein-sns-topic-2
6+
topicName: example-sns-topic-name
77
protocol: sqs
8-
endpoint: chrishein-test-sqs-2
8+
endpoint: example-sqs-queue-name

examples/snstopic.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: operator.aws/v1alpha1
22
kind: SNSTopic
33
metadata:
4-
name: chrishein-sns-topic-2
4+
name: example-sns-topic-name
55
spec:
66

examples/sqsqueue.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: operator.aws/v1alpha1
22
kind: SQSQueue
33
metadata:
4-
name: chrishein-test-sqs-2
4+
name: example-sqs-queue-name
55
spec:
66
contentBasedDeduplication: true
77
delaySeconds: 5

readme.adoc

+66-63
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,92 @@
1-
= AWS Operator
1+
= AWS Service Operator
22

3-
The AWS Operator allows you to create custom AWS specific resources using
4-
Kubernetes CRDs or Custom Resource Definitions. These help with defining your
5-
applications including all the necessary components such as Amazon RDS
6-
databases, Amazon ElasticCache resources, Amazon SQS queues and many more.
3+
The AWS Service Operator allows you to manage AWS resources using
4+
Kubernetes Custom Resource Definitions.
75

8-
Using the AWS Operator allows your to use processes like `gitops` to keep your
9-
clusters in a specified state with the internal control loop managing the
10-
lifecycle of those components.
6+
Using the AWS Service Operator enables a `gitops` workflow to drive your infrastructure to the desired state leveraging Kubernetes Custom Resource Definitions (CRD), the Kubernetes internal control loop, and AWS cloudformation orchestration. Read more about "operators" link:https://coreos.com/operators/[here].
117

12-
To make this all possible we merge together Kubernetes CRDs with an operator
13-
which interacts with Amazon Cloudformation to keep the AWS resources in-sync
14-
with the control loop.
8+
image::aws-service-operator-example.gif[]
159

16-
// TODO: Add demo screen capture
10+
== Prerequisites
11+
12+
To get started you will need
13+
14+
- a Kubernetes cluster running in AWS. Check out link:https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html[EKS] or link:https://github.com/kubernetes/kops[kops] to get started
15+
- link:https://kubernetes.io/docs/tasks/tools/install-kubectl/[kubectl]
16+
- link:https://docs.aws.amazon.com/cli/latest/userguide/installing.html[awscli]
1717

1818
== Getting Started
1919

20-
First thing that you will need to do is install an Pod to IAM management layer
21-
such as `kube2iam`. This will allow you to create an AWS IAM role that gives
22-
access to create resources. For an example policy check the
23-
`examples/iam-policy.json`.
20+
Make sure your Kubernetes cluster is up and running and you've configured your awscli for the approriate account and region you'll be working in.
21+
22+
=== IAM permissions management
23+
24+
You will need to install an IAM management layer
25+
such as `kube2iam`. This will allow you to use an AWS IAM role to manage a pod's
26+
access to AWS resources.
2427

25-
To get started with `kube2iam` go [here](https://github.com/jtblin/kube2iam)
28+
To get started with `kube2iam` go link:https://github.com/jtblin/kube2iam[here] or check out the
29+
link:https://github.com/helm/charts/tree/master/stable/kube2iam[helm chart]
2630

27-
After you have installed `kube2iam` we need to do is deploy the `aws-operator`
28-
this runs as a pod in your Kubernetes cluster and listen for new CRD's of the
29-
`aws` type and creates the resource and allocates a kubernetes `Service` to
30-
connect to it.
31+
The `aws-service-operator` runs as a pod in your Kubernetes cluster and listens for new `aws` type CRDs.
32+
When a new CRD is created the operator will create the resource in AWS via cloudformation and
33+
create a Kubernetes `Service` for access within the cluster.
3134

32-
You'll want to download the operator file like so
35+
=== Create an IAM role for the `aws-service-operator`
36+
37+
The `K8S_WORKER_NODE_IAM_ROLE` is the IAM role assigned to your kubernetes worker instances.
3338

3439
[source,shell]
35-
----
36-
wget https://raw.githubusercontent.com/christopherhein/aws-operator/master/configs/aws-operator.yaml
37-
----
40+
aws cloudformation create-stack \
41+
--stack-name aws-service-operator-role \
42+
--capabilities CAPABILITY_NAMED_IAM \
43+
--template-body file://configs/aws-service-operator-role.yaml \
44+
--parameters \
45+
ParameterKey=WorkerArn,ParameterValue=<K8S_WORKER_NODE_IAM_ROLE>
3846

39-
Then edit the file and replace `{{POD-ARN}}` with the pod ARN you created for
40-
`kube2iam`
47+
Your resulting IAM role arn should look something like `arn:aws:iam::<ACCOUNT_ID>:role/aws-service-operator`
4148

42-
Last install the manifest with the pod ARN specified.
49+
=== Deploy the aws-service-operator
4350

44-
[source,shell]
45-
----
46-
# Install RBAC
47-
kubectl apply -f aws-operator.yaml
48-
----
51+
Before applying these resources make sure to replace the following placeholders with the approriate information in `configs/aws-service-operator.yaml`
4952

50-
To test this create a file like this
53+
- `<ACCOUNT_ID>` - Your AWS Account ID
54+
- `<REGION>` - The AWS Region you're working in
55+
- `<CLUSTER_NAME>` - The name of your cluster
56+
- `<BUCKET_NAME>` - (optional) The operator stores certain things in s3 create a bucket or provide an existing bucket for the operator to use `i.e. aws s3 mb s3://foobar`
5157

52-
[source,yaml]
53-
----
54-
# s3bucket.yml
55-
apiVersion: operator.aws/v1alpha1
56-
kind: S3Bucket
57-
metadata:
58-
name: some-name-for-your-bucket
59-
spec:
60-
bucketName: some-name-for-your-bucket
61-
versioning: false
62-
logging:
63-
enabled: true
64-
prefix: "archive"
65-
tags:
66-
- key: service
67-
value: kube
68-
----
69-
70-
Then install like you would any other manifest file.
7158

59+
.1. Create the operator
60+
[source,shell]
61+
kubectl apply -f configs/aws-service-operator.yaml
62+
63+
.2. Create the cloudformation templates (cft) used by the operator
7264
[source,shell]
73-
----
74-
kubectl apply -f s3bucket.yml
75-
----
65+
kubectl apply -f examples/cloudformationtemplates
7666

77-
This will communicate directly with Cloudformation to create the S3 bucket using
67+
.3. (optional) Follow the operator logs
68+
[source,shell]
69+
kubectl logs -f -n aws-service-operator deploy/aws-service-operator
70+
71+
.4. Create an ecr repository with the operator
72+
[source,yaml]
73+
kubectl apply -f examples/ecrrepository.yaml
74+
75+
The operator will communicate directly with Cloudformation to create the ecr repository using
7876
the parameters you have passed in. If you'd like to see the progress you can
7977
view the status directly via `kubectl`.
8078

79+
.5. Check the ecr resource in Kubernetes
8180
[source,shell]
82-
----
83-
kubectl get s3buckets <bucket-name> -w
84-
// TODO: add output.
85-
----
81+
kubectl describe ecr example-repository-name
8682

87-
To learn more about the other resources please visit the documentation at
88-
link:/docs/readme.adoc[Documentation]
83+
== Removing everything
8984

85+
If you would like to tear everything down - run the following commands.
86+
87+
*IMPORTANT* this will not remove anything you created with the AWS cli (ecr repo for the operator itself, IAM roles etc.)
88+
89+
[source,shell]
90+
kubectl delete ecr example-repository-name
91+
kubectl get crd | grep ".operator.aws" | awk '{print $1}' | xargs kubectl delete crd
92+
kubectl delete -f configs/aws-service-operator.yaml

0 commit comments

Comments
 (0)