Below are some useful commands when working with Terraform, KubeOne, Kubernetes and EKS:
Note that the [default] AWS credentials are used from ~/aws/credentials
:
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
need to be specified as environment variables in your Terminal. Instead of manually setting these in each Terminal session, you can add these to:
~/.bashrc
Then, from the command line, run:
source ~/.bashrc
This will activate the latest vars for your Terminal.
You need an SSH key to successfully run the Terraform commands.
Take a look here for background on how to add your SSH key.
eval "$(ssh-agent -s)"
ssh-add -K ~/.ssh/id_rsa
Commands to run in order to setup KubeOne on AWS infrastructure via Terraform:
terraform version
kubeone version
cd/terraform && terraform init
terraform plan
terraform plan -out plan
terraform show -json plan
terraform apply
terraform output -json > tf.json
kubeone reset ./terraform/config.yaml --tfjson ./terraform/tf.json
terraform destroy
kubectl version
kubeone install config.yaml --tfjson tf.json
export KUBECONFIG=$PWD/projectname-kubeconfig
kubectl get secrets
Create env secrets:
kubectl create secret generic env-secret --from-literal=DB_USER='dbusernamehere' --from-literal=DB_PASS='dbpasshere' --from-literal=JWT_SECRET='jwtsecrethere'
kubectl create secret generic aws-secret --from-literal=aws_access_key_id='awssecretkeyhere' --from-literal=aws_secret_access_key='awssecretaccesskeyhere'
kubectl delete secrets env-secret.yaml
kubectl cluster-info
kubectl config view
kubectl get nodes
kubectl get service client -o wide
eksctl create cluster -f cluster.yaml
eksctl create cluster --name projectname-here
eksctl utils update-cluster-logging --region=eu-west-1 --cluster=projectname-here
eksctl create cluster --name=projectname-here --nodes=3 --managed --alb-ingress-access --region=${AWS_REGION}
eksctl delete cluster --name=name-here
In order to create your configmaps, deployments and services, run the following:
kubectl apply -f ./path/to/k8sfiles/env-configmap.yaml
kubectl get configmaps
kubectl apply -f ./path/to/k8sfiles/appname.deployment.yaml
kubectl get deployments
kubectl get pods
kubectl describe pods podnamehere
kubectl logs podname-7bdc944cdb-kn9wv
kubectl apply -f ./path/to/k8sfiles/appname.service.yaml
kubectl convert -f ./path/to/k8sfiles/appname.deployment.yaml --output-version apps/v1
kubectl get services
kubectl get pods -o wide
kubectl get pods podname-7bdc944cdb-s7d4n --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'
kubectl get rs
kubectl port-forward services/servicename 8080:8080
kubectl port-forward services/servicename 8100:8100
fg
to get it back into foreground: kubectl port-forward services/servicename 8080:8080 &
kubectl get machinedeployments -n kube-system
kubectl scale machinedeployment/projectname-eu-west-1a -n kube-system --replicas=2
kubectl scale machinedeployment/projectname-eu-west-1a -n kube-system --replicas=0
kubectl delete -f ./path/to/k8sfiles/appname.service.yaml
kubectl delete -f ./path/to/k8sfiles/appname.deployment.yaml
Useful commands from k8s Tutorials:
kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
kubectl describe services/kubernetes-bootcamp
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}'
echo NODE_PORT=$NODE_PORT
curl $(minikube ip):$NODE_PORT
kubectl rollout status deployments/kubernetes-bootcamp
kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=gcr.io/google-samples/kubernetes-bootcamp:v10
kubectl get deployments
kubectl get pods
kubectl rollout undo deployments/kubernetes-bootcamp
kubectl get pods
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
kubectl get services
kubectl describe services/kubernetes-bootcamp
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORT
curl $(minikube ip):$NODE_PORT
kubectl describe deployment
kubectl get pods -l run=kubernetes-bootcamp
kubectl get services -l run=kubernetes-bootcamp
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAME
kubectl label pod $POD_NAME app=v1
kubectl describe pods $POD_NAME
kubectl get pods -l app=v1
kubectl delete service -l run=kubernetes-bootcamp
kubectl get services
curl $(minikube ip):$NODE_PORT
kubectl exec -ti $POD_NAME curl localhost:8080
Further notes on k8s:
When you see values "port" and "targetPort". "port" is the port on the external IP, "targetPort" is the port on the container.
port-forward
is only a means of debugging, it is not a practical means of making containers available.