1. sudo yum update -y (update latest soft)
2. sudo yum install -y docker
3. sudo service docker start
1. sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
2. sudo chmod 666 /var/run/docker.sock
3. sudo chmod +x /usr/local/bin/docker-compose;
https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
kubectl version
kubectl cluster-info
kubectl get all
kubectl create [resource]
kubectl apply [resource]
kubectl delete [resource-name]
kubectl port-forward [name-of-pod] [external-port]:[internal-port]
https://kubernetes.io/docs/concepts/architecture/nodes/
https://kubernetes.io/docs/tutorials/kubernetes-basics/explore/explore-intro/
A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the control plane. A Node can have one or multiple pods
https://kubernetes.io/docs/concepts/workloads/pods/
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.
kubectl get pods
kubectl create -f [pod-file-name].yml eg: kubectl create -f nginx.pod.yml
kubectl apply -f [pod-file-name].yml eg: kubectl apply -f nginx.pod.yml
kubectl delete pod [name-of-pod] eg: kubectl delete pod my-nginx
kubectl describe pod [pod-name] eg: kubectl describe pod my-nginx
kubectl exec -it [pod-name] sh eg: kubectl exec -it my-nginx sh
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
Pod can be created and destroyed but can not re-created. So what happend if a Pod is destroyed? Deployment and replicasets make sure Pods stay running and can be use to scale Pods No need create Pod directly. We can use Deployment instead of Pod. A Deployment manages Pods
- Pods are managed using replicasets
- Scale replicasets will be scale Pods
- Zero downtime
kubectl get deployments
kubectl get deployments --show-labels
kubectl create -f [deployment-file-name].yml eg: kubectl create -f nginx.deployment.yml
kubectl apply -f [deployment-file-name].yml eg: kubectl apply -f nginx.deployment.yml
kubectl delete deployment [name-of-deployment] eg: kubectl delete deployment my-nginx
kubectl describe deployment [deployment-name] eg: kubectl describe deployment my-nginx
kubectl rollout status deployment [deployment-name] eg: kubectl rollout status deployment my-nginx
kubectl rollout history deployment [deployment-name] eg: kubectl rollout history deployment my-nginx
kubectl rollout undo deployment [deployment-name] eg: kubectl rollout status deployment my-nginx
https://kubernetes.io/docs/concepts/services-networking/service/
The Service API, part of Kubernetes, is an abstraction to help you expose groups of Pods over a network. Each Service object defines a logical set of endpoints (usually these endpoints are Pods) along with a policy about how to make those pods accessible.
Since Pods live and die. So we can not rely on a Pod IP address. Services provide a single point of entry for accesing one or more Pods
We have 4 Services type:
- ClusterIP: Exposes the Service on a cluster-internal IP (default).
- NodePort: Exposes the Service on each Node's IP at a static port
- LoadBalancer: Exposes the Service externally using a cloud provider's load balancer
- ExternalName: Maps the Service to the contents of the externalName field (e.g. foo.bar.example.com), by returning a CNAME record with its value. No proxying of any kind is set up
kubectl get services
kubectl create -f [service-file-name].yml eg: kubectl create -f nginx.deployment.service.yml
kubectl apply -f [service-file-name].yml eg: kubectl apply -f nginx.deployment.service.yml
kubectl delete service [name-of-service] eg: kubectl delete -f my-nginx
kubectl describe service [service-name] eg: kubectl describe service my-nginx
kubectl exec [pod-name] –it sh
apk add curl
curl http://podIp
kubectl create configmap [config-name] --from-literal=[key]=[value] eg: kubectl create configmap simple-web-app-config --from-literal=APP_COLOR=blue --from-literal=APP_MODE=prod
Use secret to store sensitive data such as password (password must be encoded data to security. Secret is not encrypted. Only encoded)
echo -n "mysql" | base64
result is: bXlzcWw=
echo -n "bXlzcWw=" | base64 --decode
result is: mysql
kubectl create secret generic [secret-name] --from-literal=[key]=[value] eg: kubectl create secret generic app-secret --from-literal=DB_HOST=mysql --from-literal=DB_USER=root --from-literal=DB_PASSWORD=123456