将AWS EKS作为GitLab的部署环境使用

继先前宣布AWS EKS(弹性Kubernetes容器服务)在全球范围内可用之后,GitLab正式宣布其支持。

我想立刻试一试!

maximilian-weisbecker-121294-unsplash.jpg

我这次想要做的事情是:

    • 既存のGitLabインスタンスで

 

    • Ruby on Railsプロジェクトに

 

    • AWS EKS クラスタを連携して

 

    Auto DevOpsのCIパイプラインを実行させる

在开始之前

    • GitLabについて

 

    • Kubernetesについて

 

    AWS EKS

Mac OS的预备工作

    Python 2 version 2.7.9+ or Python 3 version 3.3+
> python --version
Python 2.7.10
    • pip

 

    AWS CLI version 1.15.32以上
> set -x PATH /Users/jb/Library/Python/2.7/bin $PATH
> aws --version
aws-cli/1.15.34 Python/2.7.10 Darwin/17.5.0 botocore/1.10.34
    kubectl CLI v1.10以上
> kubectl version --short --client
Client Version: v1.10.2
    heptio-authenticator-aws
> curl -o heptio-authenticator-aws https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/bin/darwin/amd64/heptio-authenticator-aws
> chmod +x ./heptio-authenticator-aws
> mv heptio-authenticator-aws ~/bin/
> which heptio-authenticator-aws
/Users/jb/bin/heptio-authenticator-aws

在AWS上创建EKS集群。

准备AWS账号和环境变量

为了让本次操作在命令行上完成,我们需要准备好自己的AWS账户设置(可以使用~/.aws/config等文件,也可以使用环境变量)。

由于EKS尚未在东京地区发布,因此我们将使用us-west-2。

> set -x AWS_DEFAULT_REGION us-west-2
> echo $AWS_DEFAULT_REGION
us-west-2

另外,虽然省略了以下内容,但还是需要提前准备:

    • SSH keypair

 

    EKS権限を持つIAM Role
set -x EKS_WORKER_STACK_NAME noraneco-workers
set -x EKS_IAM_ROLE arn:aws:iam::315358830128:role/noraneco-eks

set -x EKS_CLUSTER_NAME noraneco-devops
set -x SECURITY_GROUP sg-25e4f147

set -x NODE_GROUP_NAME noraneco-workers-group
set -x NODE_AUTO_SCALING_GROUP_MIN_SIZE 1
set -x NODE_AUTO_SCALING_GROUP_MAX_SIZE 3
set -x NODE_INSTANCE_TYPE t2.medium
set -x NODE_IMAGE_ID ami-73a6e20b
set -x EKS_KEY_NAME noraneco-sshkey

set -x VPC_ID vpc-070b0065
set -x SUBNETS \'subnet-6f184c29,subnet-9da3abff,subnet-5b53792f\'
set -x EKS_SUBNETS subnet-6f184c29,subnet-9da3abff,subnet-5b53792f

创建集群

> aws eks create-cluster --name ${EKS_CLUSTER_NAME} --role-arn ${EKS_IAM_ROLE} --resources-vpc-config subnetIds=${EKS_SUBNETS},securityGroupIds=${SECURITY_GROUP}
{
    "cluster": {
        "status": "CREATING",
        "name": "noraneco-devops",
        "certificateAuthority": {},
        "roleArn": "arn:aws:iam::315358830128:role/noraneco-eks",
        "resourcesVpcConfig": {
            "subnetIds": [
                "subnet-6f184c29",
                "subnet-9da3abff",
                "subnet-5b53792f"
            ],
            "vpcId": "vpc-070b0065",
            "securityGroupIds": [
                "sg-25e4f147"
            ]
        },
        "version": "1.10",
        "arn": "arn:aws:eks:us-west-2:315358830128:cluster/noraneco-devops",
        "createdAt": 1528758865.456
    }
}

> aws eks list-clusters
{
    "clusters": [
        "noraneco-devops"
    ]
}

大约需要5分钟时间。只要执行以下命令,状态变为ACTIVE即可完成。

> aws eks describe-cluster --name ${EKS_CLUSTER_NAME}
{
    "cluster": {
        "status": "ACTIVE",
        "endpoint": "https://0FD98C1B9E833B46110E1E9272C71AD0.yl4.us-west-2.eks.amazonaws.com",
        "name": "noraneco-devops",
        "certificateAuthority": {
            "data": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRFNE1EWXhNakF5TURVME1sb1hEVEk0TURZd09UQXlNRFUwTWxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTEhnCnFqSm5EL0pZQVlWazRjS1ZGYUxpRWZMem9XWjFKSkxEbnNFckx4TEtlM1pCSUJqNUpXMGpvZjJHOSt2TnJ6K3gKeXM5ck1lL1c2WnlMakJtbVUxcFFPWlhJa1hRZDhTNTlLOXU2MVRJWkRHY0xneG1IeXp6TzVlWXBoQ2xtYUlQYQpSZWpISm9MRWtKS2FzTmhKRG94Mk0xVVRUSjVPTTZ3VjdaY1pOVVFFcU1rdnQvWHlLZFRxQ2RnM0ZNMm1Qam1UClV6T3plcFU0d1FoMXJURGtoUnlaN1hqREpiZjYvd1lZRitzRmo0VlBTNHpMM3psd2xzYnhpVlRMQS9ld01vQmwKVU5UU0FNbkliTW1XU3I5Mit5MGFyMGVUVTk1eXVNbXRYbEx0VTh5b1JXMUlkc1VrVGM0R2x4V1M4S0FmMklRYQpER05rR0JkT3pqZSttd3hBSnI4Q0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFJdmNqZ0FzL2o4eVJxeVh2bU5DNGRQVzQwRTEKWVZ0RGxvZTQzd1BnLzlneXp3WldDWHpFU1hTMURiempEbWZmTlpvek0wNVU4ZlVaeGcwZTd6QjY5VEhOd2NlaApQN1RVQ2g1WmFNbjBla21HcHcyZ3Naa01GTEVDNkFXMUU4TTZBTTlUWDVqMTBpek5LTVl1d2thUFVBeFQ1dXZICnhocEV1QkI5Q1VMaXBLb0FMS01xTmEzWnpJMU4zVEZlV3RldHkrb0pWWVp5emJQdHAyWHRnTDRVYlhxQ3FhUU4KT0JoV1JGMWhTUTQ2SXVhNStpMEFQSU9VckdYOW4zT2ZWUUtBK2tHb1g2TG1kV0pTdk93dmdqZDZOV3VGTUd4dApoNG9Zb0dMOXdGYWRMcjZuYjkzc0p5cHBnYzlLZHBMZldVTUVlMlFSb3Awd3l1bjNtM1hGZ0c5YW9jYz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo="
        },
        "roleArn": "arn:aws:iam::315358830128:role/noraneco-eks",
        "resourcesVpcConfig": {
            "subnetIds": [
                "subnet-6f184c29",
                "subnet-9da3abff",
                "subnet-5b53792f"
            ],
            "vpcId": "vpc-070b0065",
            "securityGroupIds": [
                "sg-25e4f147"
            ]
        },
        "version": "1.10",
        "arn": "arn:aws:eks:us-west-2:315358830128:cluster/noraneco-devops",
        "createdAt": 1528768731.985
    }
}

创建节点

因为可以轻松地通过Cloudformation创建节点堆栈,所以我们决定采用它。

> aws cloudformation create-stack \
    --stack-name ${EKS_WORKER_STACK_NAME} \
    --template-body https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/amazon-eks-nodegroup.yaml \
    --parameters \
        ParameterKey=ClusterName,ParameterValue=${EKS_CLUSTER_NAME} \
        ParameterKey=ClusterControlPlaneSecurityGroup,ParameterValue=${SECURITY_GROUP} \
        ParameterKey=NodeGroupName,ParameterValue=${NODE_GROUP_NAME} \
        ParameterKey=NodeAutoScalingGroupMinSize,ParameterValue=${NODE_AUTO_SCALING_GROUP_MIN_SIZE} \
        ParameterKey=NodeAutoScalingGroupMaxSize,ParameterValue=${NODE_AUTO_SCALING_GROUP_MAX_SIZE} \
        ParameterKey=NodeInstanceType,ParameterValue=${NODE_INSTANCE_TYPE} \
        ParameterKey=NodeImageId,ParameterValue=${NODE_IMAGE_ID} \
        ParameterKey=KeyName,ParameterValue=${EKS_KEY_NAME} \
        ParameterKey=VpcId,ParameterValue=${VPC_ID} \
        ParameterKey=Subnets,ParameterValue=${SUBNETS} \
    --capabilities CAPABILITY_IAM

{
    "StackId": "arn:aws:cloudformation:us-west-2:315358830128:stack/noraneco-workers/1badad40-6de7-11e8-b750-503ac931688d"
}

备忘录:实例类型t2.small可能存在不稳定的情况,建议使用t2.medium或更高的实例类型。

我会花大约10分钟时间去制作咖啡。顺便说一下,当以下命令结束时,请告诉我(请将扬声器音量调至最大)。

aws cloudformation wait stack-create-complete --stack-name $EKS_WORKER_STACK_NAME ; say "finished"

在结束后获取NodeInstanceRole的值。这对于将节点加入到集群中是必需的。

> aws cloudformation describe-stacks \
                                       --stack-name $EKS_WORKER_STACK_NAME \
                                       --query 'Stacks[0].Outputs[0].OutputValue' \
                                       | sed -E 's/.(.*)./\1/'
arn:aws:iam::315358830128:role/noraneco-workers-NodeInstanceRole-CSJHW1MNLK1Y

使用 kubectl 连接到集群

将kubeconfig创建在所喜欢的文件夹中(通常为~/.kube/)。

请将集群服务器URL、CA证书和EKS实例名称记录下来。

apiVersion: v1
clusters:
- cluster:
    server: https://361767AA37E2DAEB2C7DB16150121B9A.sk1.us-west-2.eks.amazonaws.com
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRFNE1EWXdPREE0TURFeU4xb1hEVEk0TURZd05UQTRNREV5TjFvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBT3NaCjB2bUtCOXJKZHZUSm82WjREY1BydzdoWUxNOVdNbHFHeDI0SWNFWUhxSUszdlVQd2tST2UvMUJSY3Vud01kUzMKMnMwSmpNbjVYbW1DUG13YTFpL0NjQU9Ma1U1aVRXc2k3YmJZM0FBc1hTbVg3bXJYaW1ZN01JY204a2FsdE9OVQpSdHB4dGJrckJYU0tiM0pxeXB2SlBWTkVBcWpMMksvV0c3ZzFJT0RIb1lSNnF5SGpsNHYwRjhDVTJybitYQzRpCjdBalZXL1ZpVlNpYXJEMUl2Qmh0MHl3TlRmM25NWE5TR2t6TkpwbjYzOXlaYTgrM3ZOQVdmZlYvTktxTklYRHkKN2d4RHJUVzY2dmJvam1Wdm91b0o3eXYzOCsrN3BKaHhmUEJhU0ZZenhpeklObC8ySjBXcFZ2UXJIRFMxL2FjSgo2NWZNYXRlRDUvZ0RYZVBSak84Q0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFFU3p3ZDZkSnYwSllDRlUzeG1aSjZ3QmFwTWQKVEx3aG0xbTlGNDJwYmpZUDJxZ2w0Z0NLMHZZNXE2UlplQ3Z2R1l1T3R4M0dUZEdTSjVGeS8yNkt3a0lZOTlmRQpIT2Y0MzdlMDE5QWs4bHE3WTQ4VEZBajVLejd1YmpUTzlQYVNJbDJJZ2xpamkvV0t6NUhHd1ZVWmV2VjBPQWk4CjlJM2w4NG9kd1BsRXl0eWdKRE81M2JxeXBuK3BaZkNHOXBMcmdmc2FCS1YyTGVZZkRKQk1MUFFleWM1d1hMdlEKTys0cjl5c1lYa05jZHhMeW5GTnNkc0k4bzQxaTlVSWlPYS9QZUl4eWpxMG5EcURrWXVvcEhiWWFuckFJUlV2UwpLd3ZLYlEwanhQdlZud09zOWRxVDRkTE9nMlFGeFJnMW9XRlhrYWNKRm9ORXBtYTlLR0hCdXp4aEh3dz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: aws
  name: aws
current-context: aws
kind: Config
preferences: {}
users:
- name: aws
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: heptio-authenticator-aws
      args:
        - "token"
        - "-i"
        - "noraneco-devops"

将此文件注册为kubectl的配置文件。

> set -x KUBECONFIG ./kubeconfig

通过这个,可以看到集群了。

> kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.100.0.1   <none>        443/TCP   3d

将节点加入到集群中。

在这个阶段,集群中还没有达到否认的状态。

> kubectl get nodes
No resources found.

下载AWS验证器配置映射文件,并将先前获取的NodeInstanceRole插入其中。

> curl -O https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/aws-auth-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: aws-auth
  namespace: kube-system
data:
  mapRoles: |
    - rolearn: arn:aws:iam::315358830128:role/noraneco-workers-NodeInstanceRole-CSJHW1MNLK1Y
      username: system:node:{{EC2PrivateDNSName}}
      groups:
        - system:bootstrappers
        - system:nodes

使用kubectl应用ConfigMap。

> kubectl apply -f aws-auth-cm.yaml
configmap "aws-auth" created

数秒过后,节点将加入集群。

> kubectl get nodes
NAME                                         STATUS    ROLES     AGE       VERSION
ip-172-31-13-93.us-west-2.compute.internal    Ready     <none>    57s       v1.10.3
ip-172-31-16-186.us-west-2.compute.internal   Ready     <none>    59s       v1.10.3
ip-172-31-34-141.us-west-2.compute.internal   Ready     <none>    1m        v1.10.3

命令行的工作(基本上)已经结束了。
关于EKS的感受是…手动操作太多了!!!
希望能再多自动化一些,但是好在可以将其转化为脚本或者使用terraform,所以也算不错。

2017-11-19 09.30.53.jpg

在GitLab上获取所需的信息,并且暂停使用命令行界面。

    シークレット名(あとのコマンドで必要)
> kubectl get secrets
NAME                  TYPE                                  DATA      AGE
default-token-mghhh   kubernetes.io/service-account-token   3         27m
    token
> kubectl get secret default-token-mghhh -o jsonpath="{['data']['token']}" | base64 -D
eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tbWdoaGgiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjQ0NTUxOWM4LTZkZTUtMTFlOC1hN2ExLTA2MzcxY2VmMDg1OCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.GKkBUzbm7SoSFs1DHmTavTw67jlD-XvYsb-dH4VD0vnYoF0HueCvcuYdKRn8-_-kHopmAQrHVWvMPdxxQKnWK0gDDZzLm_QQxc2kiEURiHxrYV2q3JP0mZgROqhoRkTI2hLEX7K6NNkNrWcAVwFwfqh_JS0uWuOqzNjWEhTs47RtUgzT14OH2nnlmotBC9YecTx5wVBnbQxf5EMdaT3dTiMQcUm99y5QDM_reUIUcc2eqEBnlX-3aPSupkhprHgLarnBEDkzkb2zPnnvPiQNFo7VjxkBKwtGCFY1gswveMG17J7Dwue-CqRDKIaAOd1zoXD0nagG4FWYa-wQMK_hCw
    CA Certificate
> kubectl get secret default-token-mghhh -o jsonpath="{['data']['ca\.crt']}" | base64 -D
-----BEGIN CERTIFICATE-----
MIICyDCCAbCgAwIBAgIBADANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwprdWJl
cm5ldGVzMB4XDTE4MDYxMjAyMDU0MloXDTI4MDYwOTAyMDU0MlowFTETMBEGA1UE
AxMKa3ViZXJuZXRlczCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALHg
qjJnD/JYAYVk4cKVFaLiEfLzoWZ1JJLDnsErLxLKe3ZBIBj5JW0jof2G9+vNrz+x
ys9rMe/W6ZyLjBmmU1pQOZXIkXQd8S59K9u61TIZDGcLgxmHyzzO5eYphClmaIPa
RejHJoLEkJKasNhJDox2M1UTTJ5OM6wV7ZcZNUQEqMkvt/XyKdTqCdg3FM2mPjmT
UzOzepU4wQh1rTDkhRyZ7XjDJbf6/wYYF+sFj4VPS4zL3zlwlsbxiVTLA/ewMoBl
UNTSAMnIbMmWSr92+y0ar0eTU95yuMmtXlLtU8yoRW1IdsUkTc4GlxWS8KAf2IQa
DGNkGBdOzje+mwxAJr8CAwEAAaMjMCEwDgYDVR0PAQH/BAQDAgKkMA8GA1UdEwEB
/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAIvcjgAs/j8yRqyXvmNC4dPW40E1
YVtDloe43wPg/9gyzwZWCXzESXS1DbzjDmffNZozM05U8fUZxg0e7zB69THNwceh
P7TUCh5ZaMn0ekmGpw2gsZkMFLEC6AW1E8M6AM9TX5j10izNKMYuwkaPUAxT5uvH
xhpEuBB9CULipKoALKMqNa3ZzI1N3TFeWtety+oJVYZyzbPtp2XtgL4UbXqCqaQN
OBhWRF1hSQ46Iua5+i0APIOUrGX9n3OfVQKA+kGoX6LmdWJSvOwvgjd6NWuFMGxt
h4oYoGL9wFadLr6nb93sJyppgc9KdpLfWUMEe2QRop0wyun3m3XFgG9aocc=
-----END CERTIFICATE-----

在GitLab中将集群与项目进行集成。

请参考以下链接获取如何创建默认存储类的GitLab文档:https://docs.gitlab.com/ee/user/project/clusters/eks_and_gitlab/#create-a-default-storage-class。

创建一个Ruby on Rails项目

选择New Project、Create from Template的Ruby on Rails,并创建一个新项目。

Screen Shot 2018-06-12 at 20.58.56.png

与 EKS 集群协作

打开已创建的项目,从左侧菜单选择CI/CD > Kubernetes > 添加现有集群,填写所需信息并进行注册。

Screen Shot 2018-06-11 at 20.38.33.png

如果不使用Auto DevOps,那就到此为止吧!

自动化DevOps实践

禁用基于角色的访问控制(RBAC)。

目前,Auto DevOps尚未完全支持Kubernetes的RBAC功能。
从安全角度来看,这并不理想,但为了演示目的,需要禁用RBAC功能。

> kubectl create clusterrolebinding permissive-binding \
  --clusterrole=cluster-admin \
  --user=admin \
  --user=kubelet \
  --group=system:serviceaccounts
clusterrolebinding.rbac.authorization.k8s.io "permissive-binding" created

部署Tiller/Ingress/Prometheus服务

我将以下服务部署到Kubernetes集群中的GitLab界面上。

    • Tiller

 

    • Ingress

 

    Prometheus

备忘录:有时候可能会遇到无法顺利进行的情况。在那种情况下,请使用以下命令将“删除,并通过图形界面重新安装(以下是处理Prometheus失败的方法)。

> kubectl get configmaps --all-namespaces
NAMESPACE             NAME                                      DATA      AGE
gitlab-managed-apps   ingress-controller-leader-nginx           0         13m
gitlab-managed-apps   ingress-nginx-ingress-controller          1         15m
gitlab-managed-apps   ingress.v1                                1         15m
gitlab-managed-apps   values-content-configuration-ingress      1         15m
gitlab-managed-apps   values-content-configuration-prometheus   1         11m
kube-system           aws-auth                                  1         33m
kube-system           kube-dns                                  0         42m
kube-system           kube-proxy                                1         42m

> kubectl delete configmap values-content-configuration-prometheus -n gitlab-managed-apps
configmap "values-content-configuration-prometheus" deleted

将DNS记录登记到任意的域名

在Ingress服务中,提供了外部可以访问的终端点。您可以在Route53等地方获取它并注册到域名的DNS记录中。

在 EKS 的情况下,返回的是 CNAME 而不是 IP 地址。

> kubectl describe service ingress-nginx-ingress-controller -n gitlab-managed-apps
Name:                     ingress-nginx-ingress-controller
Namespace:                gitlab-managed-apps
Labels:                   app=nginx-ingress
                          chart=nginx-ingress-0.20.3
                          component=controller
                          heritage=Tiller
                          release=ingress
Annotations:              <none>
Selector:                 app=nginx-ingress,component=controller,release=ingress
Type:                     LoadBalancer
IP:                       10.100.13.19
LoadBalancer Ingress:     acf5c578b6ded11e8a7a106371cef085-133012040.us-west-2.elb.amazonaws.com
Port:                     http  80/TCP
TargetPort:               http/TCP
NodePort:                 http  31580/TCP
Endpoints:                172.31.9.218:80
Port:                     https  443/TCP
TargetPort:               https/TCP
NodePort:                 https  30851/TCP
Endpoints:                172.31.9.218:443
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  EnsuringLoadBalancer  9m    service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   9m    service-controller  Ensured load balancer

创建默认存储类

由于EKS默认没有提供存储类,所以需要手动创建。

请参考以下链接了解更多信息:https://docs.aws.amazon.com/eks/latest/userguide/storage-classes.html

创建一个gp2-storage-class.yaml文件。

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: gp2
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
reclaimPolicy: Retain
mountOptions:
  - debug

然后,将其应用于聚类。

> kubectl create -f gp2-storage-class.yaml

storageclass.storage.k8s.io "gp2" created

> kubectl get storageclass
NAME      PROVISIONER             AGE
gp2       kubernetes.io/aws-ebs   41s

为了预防万一,将其注册为默认存储类。

> kubectl patch storageclass gp2 -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
storageclass.storage.k8s.io "gp2" patched

> kubectl get storageclass
NAME            PROVISIONER             AGE
gp2 (default)   kubernetes.io/aws-ebs   1m

启用Auto DevOps功能

回到GitLab的项目页面,点击左侧菜单中的设置(Settings) > CI/CD > 自动DevOps (Beta),选择启用自动DevOps,填写部署域名后点击保存更改,以使其生效。

Screen Shot 2018-06-12 at 21.33.13.png

执行CI Pipeline

在左侧菜单的CI/CD > 管道中选择运行管道并执行。

如果能够顺利到达这一步,将会执行以下步骤:构建、测试、正式部署和性能测试。

Screen Shot 2018-06-12 at 11.51.23.png

我要再冲一杯咖啡。

可以从CI/CD > Environments页面确认已部署到生产环境的应用程序的信息。

Screen Shot 2018-06-12 at 21.42.30.png

右侧的按钮用于在浏览器中打开应用程序,连接到应用程序容器的SSH。

如果使用多个环境,可以一眼就知道是哪个版本,可以确认运行状态和应用程序日志,非常方便。

实验结束了!

对Auto DevOps的感想是,它依然非常厉害!在GUI中,当与集群进行协作时,有一些不稳定(Bug?)的地方,但会逐渐得到改进。
由于每个项目都需要进行构建和设置的工作,这让人感到痛苦,所以希望能实现全自动化。

广告
将在 10 秒后关闭
bannerAds