Sunday, October 29th 9:00 am–12:30 pm
at #LISA17 in SF
presented by @ryanj, Developer Advocate at Red Hat
kubectl
cli tool?kubectl
Installation on linux/amd64:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
Installation on macOS:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
For other platforms, consult the official kubectl
setup guide
To verify kubectl
availability, try running:
kubectl help
minikube
Installation on linux/amd64:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
Installation on macOS:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
For other platforms, see the minikube
release notes
Optionally, customize your cluster's memory or cpu allocation:
minikube config set memory 4096
minikube config set cpus 2
to verify minikube
availability:
minikube version
minikube
provides an easy way to run Kubernetes locally:
minikube start
When you are done, halt the VM to free up system resources:
minikube stop
Need a fresh start? Delete your VM instance with:
minikube delete
--vm-driver
flag to select a specific virt providerminikube start --vm-driver=virtualbox
Check the project README
for more information about supported virtualization plugins
Still stuck? Consider signing up for OpenShift Starter or GKE: bit.ly/k8s-gcloud
Download and install a binary from the docker store
Or, use a package manager to install:
brew install docker
To verify docker
availability:
docker version
To reference minikube's docker daemon from your host, run:
eval $(minikube docker-env)
Install git
using the instructions here:
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
To verify git
availability, run:
git version
Verify that your local Kubernetes environment is ready by running:
kubectl version
The output should include your kubectl
version info, and the release version of the kubernetes API server (when available)
kubectl
Try using kubectl
to list resources by type:
kubectl get nodes
Request the same info, but output the results as structured yaml:
kubectl get nodes -o yaml
Fetch an individual resource by type/id
, output as json
:
kubectl get node/minikube -o json
View human-readable API output:
kubectl describe node/minikube
List resources by type:
kubectl get pods
Create a new resource based on a json object specification:
curl https://raw.githubusercontent.com/ryanj/metrics-k8s/master/pod.json
kubectl create -f https://raw.githubusercontent.com/ryanj/metrics-k8s/master/pod.json
List resources by type:
kubectl get pods
Fetch a resource by type and id, output the results as yaml
:
kubectl get pod metrics-k8s -o yaml
Notice any changes?
Expose the pod by creating a new service
(or "loadbalancer"):
kubectl expose pod/metrics-k8s --port 2015 --type=NodePort
Contact your newly-exposed pod using the associated service id:
minikube service metrics-k8s
Schedule a pod to be deleted:
kubectl delete pod metrics-k8s
Contact the related service. What happens?:
minikube service metrics-k8s
Delete the service:
kubectl delete service metrics-k8s
Create a specification for your deployment
:
kubectl run metrics-k8s --image=quay.io/ryanj/metrics-k8s \
--expose --port=2015 --service-overrides='{ "spec": { "type": "NodePort" } }' \
--dry-run -o yaml > deployment.yaml
View the generated deployment spec file:
cat deployment.yaml
Bug?:You may need to edit this file, adding "---
" (on it's own line) between resource 1 and resource 2 for a workaround.
Can you think of another way to fix this issue? json compatible?
Create a new resource based on your yaml specification:
kubectl create -f deployment.yaml
List resources by type:
kubectl get po,svc
Connect to your new deployment via the associated service id:
minikube service metrics-k8s
Scale up the metrics-k8s
deployment to 3 replicas:
kubectl scale deploy/metrics-k8s --replicas=3
List pods:
kubectl get po
Edit deploy/metrics-k8s
, setting spec.replicas
to 5
:
kubectl edit deploy/metrics-k8s -o json
Save and quit. What happens?
kubectl get pods
Watch for changes to pod
resources:
kubectl get pods --watch
In another terminal, delete several pods by id:
kubectl delete pod $(kubectl get pods | grep ^metrics-k8s | cut -f1 -s -d' ' | head -n 3 | tr '\n' ' ')
What happend? How many pods remain?
kubectl get pods
Watch deployments (leave this running until the 'cleanup' section):
kubectl get deploy --watch
View the current state of your deployment:
minikube service metrics-k8s
Update your deployment's image spec to rollout a new release:
kubectl set image deploy/metrics-k8s metrics-k8s=quay.io/ryanj/metrics-k8s:v1
Reload your browser to view the state of your deployment
kubectl get rs,deploy
View the list of previous rollouts:
kubectl rollout history deploy/metrics-k8s
Rollback to the previous state:
kubectl rollout undo deployment metrics-k8s
Reload your browser to view the state of your deployment
Cleanup old resources if you don't plan to use them:
kubectl delete service,deployment metrics-k8s
Close any remaining --watch
listeners
minikube
with
minikube
Kubernetes provides portable abstractions for working with distributed solitions:
As web development is increasingly being carried out using container-based microservices:
git clone https://github.com/ryanj/metrics-k8s
cd metrics-k8s
npm install
npm start
docker-env
is configured for minikubedocker build . -t yourname/metrics-k8s:v1
metrics-review.yaml
, setting the container image
to:
yourname/metrics-k8s:v1
kubectl apply -f metrics-review.yaml
minikube service metrics-review
kubectl
cli tool?on completing the
tutorial at #LISA17 in SF
Please remember to complete your tutorial evaluation!