01 Jul Install Jenkins on Kubernetes at AWS
eksctl create cluster –name myekscluster –region us-east-1 –zones us-east-1a,us-east-1b –managed –nodegroup-name mynodegroup
kubectl get svc
aws ec2 describe-vpcs
{
“Vpcs”: [
{
“CidrBlock”: “172.31.0.0/16”,
“DhcpOptionsId”: “dopt-93a28ae8”,
“State”: “available”,
“VpcId”: “vpc-a828a7d2”,
“OwnerId”: “417501541667”,
“InstanceTenancy”: “default”,
“CidrBlockAssociationSet”: [
{
“AssociationId”: “vpc-cidr-assoc-e837af84”,
“CidrBlock”: “172.31.0.0/16”,
“CidrBlockState”: {
“State”: “associated”
}
}
],
“IsDefault”: true
},
{
“CidrBlock”: “192.168.0.0/16”,
“DhcpOptionsId”: “dopt-93a28ae8”,
“State”: “available”,
“VpcId”: “vpc-079de9a064ccfb155”,
“OwnerId”: “417501541667”,
“InstanceTenancy”: “default”,
“CidrBlockAssociationSet”: [
{
{
“Vpcs”: [
{
“CidrBlock”: “172.31.0.0/16”,
“DhcpOptionsId”: “dopt-93a28ae8”,
“State”: “available”,
“VpcId”: “vpc-a828a7d2”,
“OwnerId”: “417501541667”,
“InstanceTenancy”: “default”,
“CidrBlockAssociationSet”: [
{
“AssociationId”: “vpc-cidr-assoc-e837af84”,
“CidrBlock”: “172.31.0.0/16”,
“CidrBlockState”: {
“State”: “associated”
}
}
],
“IsDefault”: true
},
{
“CidrBlock”: “192.168.0.0/16”,
“DhcpOptionsId”: “dopt-93a28ae8”,
“State”: “available”,
“VpcId”: “vpc-079de9a064ccfb155”,
“OwnerId”: “417501541667”,
“InstanceTenancy”: “default”,
“CidrBlockAssociationSet”: [
{
“AssociationId”: “vpc-cidr-assoc-0d68abff5d9b1d2ed”,
“CidrBlock”: “192.168.0.0/16”,
“CidrBlockState”: {
“State”: “associated”
}
}
],
“IsDefault”: false,
“Tags”: [
{
“Key”: “aws:cloudformation:stack-id”,
“Value”: “arn:aws:cloudformation:us-east-1:417501541667:stack/eksctl-myekscluster-cluster/1a18ad70-d9f2-11eb-9746-0eecabf51e5d”
},
{
“Key”: “alpha.eksctl.io/cluster-name”,
“Value”: “myekscluster”
},
{
“Key”: “Name”,
“Value”: “eksctl-myekscluster-cluster/VPC”
},
{
“Key”: “aws:cloudformation:logical-id”,
“Value”: “VPC”
},
{
“Key”: “aws:cloudformation:stack-name”,
“Value”: “eksctl-myekscluster-cluster”
},
{
“Key”: “alpha.eksctl.io/eksctl-version”,
“Value”: “0.54.0”
},
{
“Key”: “eksctl.cluster.k8s.io/v1alpha1/cluster-name”,
“Value”: “myekscluster”
}
]
}
]
}
aws ec2 create-security-group \
–region us-east-1 \
–group-name efs-mount-sg \
–description “Amazon EFS for EKS, SG for mount target” \
–vpc-id vpc-079de9a064ccfb155
aws ec2 authorize-security-group-ingress \
–group-id sg-06742eada572ce1a4 \
–region ap-east-1 \
–protocol tcp \
–port 2049 \
–cidr 192.168.0.0/16
aws efs create-file-system \
–creation-token creation-token \
–performance-mode generalPurpose \
–throughput-mode bursting \
–region ap-east-1 \
–tags Key=Name,Value=MyEFSFileSystem \
–encrypted
{
“OwnerId”: “417501541667”,
“CreationToken”: “creation-token”,
“FileSystemId”: “fs-d8a6c06c”,
“FileSystemArn”: “arn:aws:elasticfilesystem:us-east-1:417501541667:file-system/fs-d8a6c06c”,
“CreationTime”: “2021-06-30T23:15:12+00:00”,
“LifeCycleState”: “creating”,
“Name”: “MyEFSFileSystem”,
“NumberOfMountTargets”: 0,
“SizeInBytes”: {
“Value”: 0,
“ValueInIA”: 0,
“ValueInStandard”: 0
},
“PerformanceMode”: “generalPurpose”,
“Encrypted”: true,
“KmsKeyId”: “arn:aws:kms:us-east-1:417501541667:key/19fe7599-e109-4492-8abd-8850bee8874f”,
“ThroughputMode”: “bursting”,
“Tags”: [
{
“Key”: “Name”,
“Value”: “MyEFSFileSystem”
}
]
}
aws ec2 describe-instances –filters Name=vpc-id,Values=vpc-079de9a064ccfb155 –query ‘Reservations[*].Instances[].SubnetId’
[
“subnet-0180b9478e0a0bbcb”,
“subnet-0eef000ed9e8aac19”
]
aws efs create-mount-target \
–file-system-id fs-d8a6c06c \
–subnet-id subnet-0180b9478e0a0bbcb \
–security-group sg-06742eada572ce1a4 \
–region us-east-1
{
“OwnerId”: “417501541667”,
“MountTargetId”: “fsmt-e6d04553”,
“FileSystemId”: “fs-d8a6c06c”,
“SubnetId”: “subnet-0180b9478e0a0bbcb”,
“LifeCycleState”: “creating”,
“IpAddress”: “192.168.24.131”,
“NetworkInterfaceId”: “eni-0246d630236b9b66a”,
“AvailabilityZoneId”: “use1-az2”,
“AvailabilityZoneName”: “us-east-1a”,
“VpcId”: “vpc-079de9a064ccfb155”
}
aws efs create-mount-target \
–file-system-id fs-d8a6c06c \
–subnet-id subnet-0eef000ed9e8aac19 \
–security-group sg-06742eada572ce1a4 \
–region us-east-1
{
“OwnerId”: “417501541667”,
“MountTargetId”: “fsmt-c9d0457c”,
“FileSystemId”: “fs-d8a6c06c”,
“SubnetId”: “subnet-0eef000ed9e8aac19”,
“LifeCycleState”: “creating”,
“IpAddress”: “192.168.49.116”,
“NetworkInterfaceId”: “eni-04c078920ac933f6f”,
“AvailabilityZoneId”: “use1-az4”,
“AvailabilityZoneName”: “us-east-1b”,
“VpcId”: “vpc-079de9a064ccfb155”
}
aws efs create-access-point –file-system-id fs-d8a6c06c \
–posix-user Uid=1000,Gid=1000 \
–root-directory “Path=/jenkins,CreationInfo={OwnerUid=1000,OwnerGid=1000,Permissions=777}”
{
“ClientToken”: “424a8ddc-3106-41f6-a31c-a49c2bc1cd72”,
“Tags”: [],
“AccessPointId”: “fsap-0d3f3dcb64fdafa3f”,
“AccessPointArn”: “arn:aws:elasticfilesystem:us-east-1:417501541667:access-point/fsap-0d3f3dcb64fdafa3f”,
“FileSystemId”: “fs-d8a6c06c”,
“PosixUser”: {
“Uid”: 1000,
“Gid”: 1000
},
“RootDirectory”: {
“Path”: “/jenkins”,
“CreationInfo”: {
“OwnerUid”: 1000,
“OwnerGid”: 1000,
“Permissions”: “777”
}
},
“OwnerId”: “417501541667”,
“LifeCycleState”: “creating”
}
sudo apt install git -y
kubectl apply -k “github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/?ref=master”
serviceaccount/efs-csi-controller-sa created
clusterrole.rbac.authorization.k8s.io/efs-csi-external-provisioner-role created
clusterrolebinding.rbac.authorization.k8s.io/efs-csi-provisioner-binding created
deployment.apps/efs-csi-controller created
daemonset.apps/efs-csi-node created
csidriver.storage.k8s.io/efs.csi.aws.com configured
storageclass.yaml
nano storageclass.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: efs-sc
provisioner: efs.csi.aws.com
persistentvolume.yaml
nano persistentvolume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: efs-pv
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
– ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc
csi:
driver: efs.csi.aws.com
volumeHandle: fs-d8a6c06c::fsap-0d3f3dcb64fdafa3f
persistentvolumeclaim.yaml
nano persistentvolumeclaim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: efs-claim
spec:
accessModes:
– ReadWriteMany
storageClassName: efs-sc
resources:
requests:
storage: 5Gi
kubectl apply -f \
storageclass.yaml,persistentvolume.yaml,persistentvolumeclaim.yaml
storageclass.storage.k8s.io/efs-sc created
persistentvolume/efs-pv created
persistentvolumeclaim/efs-claim created
kubectl get sc,pv,pvc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
storageclass.storage.k8s.io/efs-sc efs.csi.aws.com Delete Immediate false 26s
storageclass.storage.k8s.io/gp2 (default) kubernetes.io/aws-ebs Delete WaitForFirstConsumer false 57m
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/efs-pv 5Gi RWX Retain Bound default/efs-claim efs-sc 26s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/efs-claim Bound efs-pv 5Gi RWX efs-sc 26s
helm repo add bitnami https://charts.bitnami.com/bitnami
“bitnami” has been added to your repositories
helm install jenkins bitnami/jenkins –set rbac.create=true,master.servicePort=80,master.serviceType=LoadBalancer,persistence.existingClaim=efs-claim
export SERVICE_IP=$(kubectl get svc –namespace default jenkins –template “{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}”)
echo “Jenkins URL: http://$SERVICE_IP/”
printf $(kubectl get svc –namespace default jenkins –template “{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}”);echo
a59d171d9ad1c4bdd9aaa6596b4d1cc8-1611967179.us-east-1.elb.amazonaws.com
echo Username: user
printf $(kubectl get secret –namespace default jenkins -o jsonpath=”{.data.jenkins-password}” | base64 –decode);echo
JSCfT2nN2c
helm uninstall jenkins
https://aws.amazon.com/cn/blogs/storage/deploying-jenkins-on-amazon-eks-with-amazon-efs/
https://www.cnblogs.com/faberbeta/p/14247882.html
No Comments