- Pull the source code
git clone https://github.com/TranHoang/kubernetes.git
vagrant up
vagrant ssh
Following these steps to create a micro cluster with one master and one node on AWS
- Config enviroment variable
kubernetes
└───bin
│ │ create_aws_cluster.sh
└───env
│ │ aws_rsa.pub
│ │ aws.env
│ │ cluster.env
│ README.md
│ setup.sh
| Vagrantfile
-
aws_rsa.pub kops use public key to create the cluster on AWS
-
aws.env AWS enviroment variable
AWS_ACCESS_KEY_ID="AWS Access key id goes here." AWS_SECRET_ACCESS_KEY="AWS secret access key goes here." S3_BUCKET_NAME="kops use this bucketname to store the cluster state." AWS_AVAILABE_ZONE_NAME="AWS region availability-zones. Example: ap-southeast-1a."
-
cluster.env AWS enviroment variable
CLUSTER_NAME="kops need a cluster name to deploy. It's also a domain name."
-
Config AWS Route 53
Create a public hosted zones in AWS Route 53
-
Config DNS in the domain panel Added NS Record with host name is the AWS Route 53 values. For example
-
Create 1 micro cluster
./bin/create_aws_cluster.sh
- Wait for a few minutes then check the cluster is ready for deployment
kops validate cluster --state=s3://kops-state-b24b
- Once the cluster is up, master and node are ready then run the scrips below to deploy a simple echoserver to AWS
kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port 8080
kubectl expose deployment hello-minikube --type=NodePort
kubectl get service
- Start minikube cluster
minikube start
- Build the helloworld image
./bin/build_image.sh
./bin/push_image.sh
- Create pod on minikube
./bin/create_pods.sh
- Verify pod status
kubectl describe pod helloworld.example.com
- There are 2 ways to expose the pod
5.1 Forward pod's port then we can access via localhost
kubectl port-forward helloworld.example.com 8081:3000
curl http://localhost:8081
5.2 Create a service
kubectl expose pod helloworld.example.com --type=NodePort --name helloworld-service
minikube service helloworld-service --url
- Build the helloworld image
./bin/build_image.sh
./bin/push_image.sh
- Create a cluster
./bin/create-aws-cluster.sh
- Check cluster status
./bin/validate-cluster.sh
- Once the cluster is up, master and node are ready then we deploy the helloworld application cluster
./bin/create-pods.sh
./bin/create-services.sh
- Create an alias record set in hosted zones and select the load balancing service in the Alias Target dropdown.
- Access the http://helloworld.kubernetes.fullstack.ws
./bin/deploy.sh
kubectl expose deployment helloworld-deployment --type=NodePort
minikube service helloworld-deployment --url
- Attach to a process that is already running inside an existing container.
kubectl attach {POD_NAME} -c [CONTAINER_NAME]
- Execute a shell in a container inside a pod
kubectl exec -it {POD_NAME} -c [CONTAINER_NAME] -- /bin/bash
- Describe a service
kubectl describe {SERVICE_NAME}
- Update an image for a specific container in a deployment
./bin/deploy-update-image.sh -c [CONTAINER_NAME] -i [Docker hub image uri]
Example
./bin/deploy-update-image.sh -c k8s-demo -i tranhoang/helloworld:2.0
- Grant permission for vagrant ubuntu user to execute the docker. Execute the following command then re-ssh to the vagrant box
sudo usermod -a -G docker $USER