Skip to content

Instantly share code, notes, and snippets.

@Fazzani
Last active April 30, 2018 08:04
Show Gist options
  • Save Fazzani/aa5d77d519c982867a30dc6c873b2690 to your computer and use it in GitHub Desktop.
Save Fazzani/aa5d77d519c982867a30dc6c873b2690 to your computer and use it in GitHub Desktop.
kubernetes kops aws

K8S installation with KOPS

KOPS_STATE_STORE : is the source of truth for all clusters managed by Kops

  1. Kubectl Installation
apt-get update && apt-get install -y apt-transport-https &&  apt-get install -y curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubectl
  1. Kops installation
wget https://github.com/kubernetes/kops/releases/download/1.9.0/kops-linux-amd64
chmod +x kops-linux-amd64
mv kops-linux-amd64 /usr/local/bin/kops
  1. Aws cli install & configure

  2. Installation

# pip install
pip -V || sudo apt-get install python-pip
# aws cli install
aws --version || pip install awscli --upgrade --user
# Add Aws to the path
export PATH=~/.local/bin:$PATH
  1. Configuration
aws configure
AWS Access Key ID [None]: xxxxxxxxxxxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxxxxxxxx
Default region name [None]: eu-west-1
Default output format [None]: json
# export default AWS_PROFILE
export AWS_PROFILE=default

aws autocomplete install

complete -C '$(which aws_completer)' aws
  1. Create a route53 domain for your cluster
  2. Create an S3 bucket to store your clusters state

S3 bucket used to store all cluster configuration information

# Configurer les zones de dispo de KOPS :
export AWS_AVAILABILITY_ZONES="$(aws ec2 describe-availability-zones --query 'AvailabilityZones[].ZoneName' --output text | awk -v OFS="," '$1=$1')"

# Create the S3 bucket using
export S3_BUCKET=kops-state-store-$(cat /dev/urandom | LC_ALL=C tr -dc "[:alpha:]" | tr '[:upper:]' '[:lower:]' | head -c 32)
export KOPS_STATE_STORE=s3://${S3_BUCKET}
# S3 bucket creation
aws s3 mb $KOPS_STATE_STORE
# Activate S3 versioning
aws s3api put-bucket-versioning --bucket $S3_BUCKET --versioning-configuration Status=Enabled
  1. Build your cluster configuration
# Create ssh default user ssh key
ssh-keygen -t rsa -b 4096 -C "[email protected]"
# Créer un cluster dans un vpc privé
kops create cluster --name hef.cluster.k8s.local --master-count 3 --node-count 5 --zones $AWS_AVAILABILITY_ZONES --topology private --networking kube-router
# Lister les clusters existants
kops get cluster
# Editer un cluster
kops edit cluster hef.cluster.k8s.local
# Editer le fichier de config des nodes
kops edit ig --name=hef.cluster.k8s.local nodes
# Editer la config d'un master
kops edit ig --name=hef.cluster.k8s.local master-eu-west-1a
  1. Create the cluster in AWS
# Mettre a jour le cluster :
kops update cluster hef.cluster.k8s.local --yes
# Valider l'état du cluster :
kops validate cluster
# Récupérer le DNS du load balancer d'api :
aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].DNSName'

Various

  1. Installer le dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
  1. Récupérer le mot de passe admin
kops get secrets admin --type secret -oplaintext
  1. Updating cluster configuration
kops rolling-update cluster --yes
  1. Cleanup
kops delete cluster hef.cluster.k8s.local --yes
  1. Kubernetes upgrading version (Manual update)
kops edit cluster $NAME
set the KubernetesVersion to the target version (e.g. v1.3.5)
kops update cluster $NAME to preview, then kops update cluster $NAME --yes
kops rolling-update cluster $NAME to preview, then kops rolling-update cluster $NAME --yes

References

Installing Kubernetes on AWS with kops (Kubernetes doc off) create cluster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment