Created
October 27, 2019 05:04
-
-
Save mikepfeiffer/64c40013d263f4f96bdb702b11e90d3d to your computer and use it in GitHub Desktop.
CreateAKSCluster.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create a resource group for the serivces we're going to create | |
az group create --name "AKS-Demo" --location westeurope | |
az group show --name "AKS-Demo" | |
#Get a list of the versions available | |
az aks get-versions --location westeurope -o table | |
#Check out some of the options available to us when creating our managed cluster | |
az aks create -h | more | |
#Create our AKS managed cluster | |
az aks create \ | |
--resource-group "AKS-Demo" \ | |
--generate-ssh-keys \ | |
--name CSCluster \ | |
--kubernetes-version 1.12.7 \ | |
--node-count 2 #default Node count is 3 | |
az aks show --resource-group "AKS-Demo" --name CSCluster | more | |
#Get our cluster credentials and merge the configuration into our existing config file | |
#This will allow us to connect to this system remotely using certificate based user authentication | |
az aks get-credentials --resource-group "AKS-Demo" --name CSCluster | |
#List our currently available contexts | |
kubectl config get-contexts | |
#set our current context to the Azure context | |
kubectl config use-context CSCluster | |
#run a command to communicate with our cluster. | |
kubectl get nodes | |
#Get a list of running pods, we'll look at the system pods since we don't have anything running. | |
kubectl get pods --all-namespaces | |
#Listing and Inspecting your cluster, pods, services and more. | |
kubectl cluster-info | |
#Additional information about each node in the cluster. | |
kubectl get nodes -o wide | |
#Let's get a list of pods...but there isn't any running. | |
kubectl get pods | |
#True, but let's get a list of system pods. A namespace is a way to group resources together. | |
kubectl get pods --namespace kube-system | |
kubectl get namespace | |
#Let's get additional information about each pod. | |
kubectl get pods --namespace kube-system -o wide | |
#Now let's get a list of everything that's running in all namespaces | |
kubectl get all --all-namespaces | more | |
#Asking kubernetes for the resources it knows about | |
#Let's look at the headers in each column. Name, Alias/shortnames, API Group (or where that resource is in the k8s API Path), | |
#Is the resource in a namespace, for example StorageClass issn't and is available to all namespaces and finally Kind...this is the object type. | |
kubectl api-resources | head -n 10 | |
#We can easily filter using group | |
kubectl api-resources | grep pod | |
#Explain an indivdual resource in detail | |
kubectl explain pod | more | |
kubectl explain pod.spec | more | |
kubectl explain pod.spec.containers | more | |
#You'll soon find your favorite alias | |
kubectl get no | |
#Let's take a closer look at our nodes using Describe | |
#Check out Name, Taints, Conditions, Addresses, System Info, Non-Terminated Pods, and Events | |
NODE0=$(kubectl get nodes | awk '{print $1}' | grep '0$') | |
kubectl describe nodes $NODE0 | more | |
#Imperatively working with your cluster. Run will "generate" a Deployment by default. | |
#This is pulling a specified image from Google's container registry. | |
#kubectl run, will convert a pod creation into a "Deployment generation" | |
#http://kubernetes.io/docs/user-guide/kubectl-conventions/#generators | |
kubectl run hello-world \ | |
--image=gcr.io/google-samples/hello-app:1.0 | |
#But let's deploy a single pod too... | |
kubectl run hello-world-pod \ | |
--image=gcr.io/google-samples/hello-app:1.0 \ | |
--generator=run-pod/v1 | |
#Let's follow our pod and deployment status | |
kubectl get pods | |
kubectl get deployment #Remember deployments are made of ReplicaSets | |
kubectl get pods -o wide | |
#Back on the Master, we can pull the logs from the container. Which is going to be anything written to stdout. | |
#Maybe something went wrong inside our app, and our pod won't start. This is useful for troubleshooting. | |
kubectl logs hello-world-pod | |
#Starting a process inside a container inside a pod. | |
#We can use this to launch any process as long as the executable/binary is in the container. | |
#Launch a shell into the container. Callout that this is on the *pod* network. | |
kubectl exec -it hello-world-pod -- /bin/sh | |
hostname | |
ip addr | |
exit | |
#Remember that first kubectl run we executed, it created a Deployment for us. | |
#Let's look more closely at the deployment | |
#Deployments are made of ReplicaSets! | |
kubectl get deployment hello-world | |
kubectl get replicaset | |
kubectl get pods | |
#Let's take a closer look at our pod. | |
#Walk through the pods Events... | |
#Name, Containers, Ports, Conditions, and Events. | |
#Deployments are made of ReplicaSets! | |
kubectl describe deployment hello-world | more | |
#Let's see what describe can tell us about a deployed Pod. | |
#Check out the Name, Node, Status, Containers, and events. | |
kubectl get pods | |
kubectl describe pods hello-world-d778d9d84-dlsqb | more | |
#Expose the Deployment as a Serivce. | |
#This will create a Service for the ReplicaSet behind the Deployment | |
#We are exposing our serivce on port 80, connecting to an application running on 8080 in our pod. | |
#Port: Interal Cluster Port, the Service's port. You will point cluster resources here. | |
#TargetPort: The Pod's Serivce Port, your application. That one we defined when we started the pods. | |
kubectl expose deployment hello-world --port=80 --target-port=8080 --type=LoadBalancer | |
#Check out the IP: and Port:, that's where we'll access this service. | |
kubectl get service hello-world | |
#We can also get that information from using describe | |
kubectl describe service hello-world | |
kubectl get service hello-world | |
curl http://168.61.149.206 | |
#Using kubectl to generate yaml or json files of our imperitive configuration. | |
kubectl get service hello-world -o yaml | |
kubectl get service hello-world -o json | |
#Exported resources are stripped of cluster-specific information. | |
kubectl get service hello-world -o yaml --export > service-hello-world.yaml | |
kubectl get deployment hello-world -o yaml --export > deployment-hello-world.yaml | |
ls *.yaml | |
#Let's remove everything we created imperitively and start over using a declarative model | |
kubectl delete service hello-world | |
kubectl delete deployment hello-world | |
kubectl delete pod hello-world-pod | |
kubectl get all | |
#Deploying applications declaratively | |
#we can use apply to create our resources from yaml. | |
kubectl apply -f deployment-hello-world.yaml | |
kubectl apply -f service-hello-world.yaml | |
#This re-creates everything we created, but in yaml | |
kubectl get all | |
#scale up our deployment | |
vi deployment-hello-world.yaml | |
Change replicas from 1 to 2 | |
replicas: 2 | |
#update our configuration with apply | |
kubectl apply -f deployment-hello-world.yaml | |
#And check the current configuration of our deployment | |
kubectl get deployment hello-world | |
#Let's clean up our deployment and remove everything | |
kubectl delete deployment hello-world | |
kubectl delete service hello-world | |
kubectl get all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment