This is a collection of notes from the internet on how to do things kubernetes
- Minikube: For local developement
- kops and Kubeadm: For clouds and bare metal
General Management Tools
- Dashboard: Visualization
- Kubefed: For Larger cluster federation
- Kompose: For Exporting from docker with compose
- Helm: For Large application management
When creating a cluster from an image, you can also use the run command.
kubectl run give-name-of-cluster --image repo-name/image-name:latest
Common way (from file): To use a yaml file within your local computer, use the command
kubectl create -f file-2-deploy.yaml
Multiple files:
kubectl create -f file-1-deploy.yaml file-2-deploy.yaml
Whole directory: Must have .yaml files
kubectl create ./cluters
URL:
kubectl apply -f https://github.com/Cosmos-it/k8s-commands/blob/master/sample.yaml
Deploy sample infrastructure:
kubectl apply -f sample.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample
spec:
containers:
- name: sample
image: ubuntukubectl get podsreturns no results.kubectl get pods --all-namespacesreturns all our results.kubectl get namespacesReturns just the namespaces
kubectl get pods --sort-by=.metadata.namesorts pods by namekubectl get pods -o wide --all-namespacesreturns more detailskubectl get pods/cart-dev -n cart -o jsonreturns the pod jsonkubectl get pods -n cart -o=jsonpath="{..image}" -l app=cart-devsearches cart-dev, and returns the image based on the jsonpathkubectl get pods --all-namespaces -o jsonpath="{.items[*]- .spec.containers[*].image}"all container images running
kubectl delete pods --alldeletes all pods in the default namespacekubectl delete pods -n cart --alldeletes all pods in the cart namespacekubectl delete pods -l env=staging -n socialDeletes the pods in the social namespace that match the staging environment
To use kops to run your own kubernetes cluster, you will need to the following.
Install and set
- kops
- kubectl
- AWS credentials
- AWS CLI tools
- Set up IAM account: Give ut full access to s3, EC2, Route53, and IAM
- Create DNS record for the kubernetes services
export NAME=mycluster.k8s.localexport KOPS_STATE_STORE=s3://prefix-example-com-state-store
kops create cluster \ --zones use-west-2b \ ${NAME}
Note: Kops create cluster command will result into a configuration file for what your cluster is going tro look like
Important: Important to verify that everything is the way kops expects.
kops edit cluster cluster-name
kops update cluster cluster-name
Build the cluster per spec
kubectl get nodesalert when nodes are readykops validate clusterverify that everything works- You can use terraform to provison that nodes. (Read more terraform)
Microservices: An oriented architecture that structures the entire application as a collection of loosely coupled services.