AKS Setup - amitbhilagude/userfullinks GitHub Wiki

  1. Install Docker Desktop
    1. Enable the Kubernetes option. It will start installing all respective dependencies and Docker and Kubernetes Status will become Green with running state.
  2. Enable UI Dashboard locally
    1. Install Dashboard
      1. kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.1.0/aio/deploy/recommended.yaml
    2. UI Dashboard is secured and it will require a token to access. The new user will be created into Kubernetes and get that token for that user. Create a Sample User Account that can Access the Dashboard via Token
      1. kubectl apply -f https://gist.githubusercontent.com/dahlsailrunner/bbd453f3bb6259b66c08a70d0908283f/raw/5727723217e2df4b65d8933adf04d009cfb0fe3f/local-dashboard-account.yml
    3. Grab the Token for the Sample User
      1. $(kubectl -n kubernetes-dashboard get secret | sls admin-user | ForEach-Object { $_ -Split '\s+' } | Select -First 1)
    4. Enable Access to the Dashboard Service
      1. start kubectl proxy
    5. Explore the Dashboard
      1. http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
  3. POD
    1. POD commands
      1. Create a Pod without Yaml
        1. kubectl run [podname ] --image= nginx:alpine
      2. Get all Pods
        1. kubectl get pods
      3. Expose pod port to available over internet
        1. kubectl port-forward [name of pod] 8080:80
        2. 8080 is an external port and 80 is the internal port
      4. Delete a Pod
        1. kubectl delete pod [name of pod]
        2. Kubernetes detects and the pod is deleted and it creates again. If you run in prod which has health probes.
      5. Delete a pod permanently
        1. kubectl delete deployment [name of deployment]
      6. Creating a pod using YAML. Yaml file sample for the pod is Here
        1. kubectl create -f file.pod.yml
        2. Perform a "trial" create and also validate the YAML
          1. kubectl create -f file.pod.yml --dry-run --validate=true
        3. Alternate way to create or apply changes to a Pod from YAML
          1. kubectl apply -f file.pod.yml
        4. Use save config when you want to use kubectl apply in the future. This will save yaml filed in pod configuration under annotations. You can check it later anytime about the last YAML used.
          1. kubectl create -f file.pod.yml --save-config
      7. Deleting a pod
        1. Deleting a pod
          1. kubectl delete pod [name of pod]
        2. Deleting a pod using Yaml file which was created earlier
          1. kubectl delete f file.pod.yml
      8. Execution inside a pod
        1. Go inside pod kubectl exec [podname] -it sh
      9. Pod Health
        1. Pod Health will be added in the yaml file.
        2. Liveness Prob
          1. Check Pod's health and decide when to restart as per the configuration mentioned in the yaml file.
          2. It has HTTP get to request which contains a path which pings
          3. It also has additional configuration about frequency etc.
        3. Readiness Prob
          1. Check Pod if it is ready to accept the request
          2. It has HTTP get to request which contains a path which pings
  4. Deployment
    1. Overview
      1. Deployment is used to deploy resources like Pods with additional features like Replica, Xero downtime, etc.
      2. Deployment is wrapped on top of the Replica set which manages the scalability.
      3. All deployments are managed using deployment command so we don't need to use create POD commands
      4. Deployment yaml sample is available here.
    2. Command
      1. kubectl apply -f deployment.yml has replica properties to mention how many replicas count to be created. it will also have labels that are used to group the application and choose the template based on labels.
      2. kubectl get deployments --show-labels
      3. kubectl get all
  5. Service
    1. Overview
      1. Service is another kind that is used to communicate POD.
      2. Service can find Pods based on labels.
      3. Service also supports Loadbalancing and Node Port functionality.
      4. Example for all below types of services are here
    2. ClusterIP Service
      1. Every pod gets a dynamic IP address allocated and will be difficult to use that IP.
      2. Service of type ClusterIP is used by Pods to communicate internally. If we create a cluster IP Service, Service will take care of load balancing and the request will route one of the pods. You can test this by going inside one of the pods, try to access another pod URL using cluster IP.
    3. NodePort Service
      1. NodePort service is used to map external with internal port.
    4. Load Balancing Service
      1. Used for load balancing and map the external IP.
  6. Volume
    1. Volume is used to store or access persistent storage data in Containers
    2. EmptyDir Volume
      1. This volume's lifespan depends on the pod. If the Pods gets deleted or restarted, this volume will be deleted
      2. This is a good option if you want to access data from one container to another within pod
    3. Hostpath Volume
      1. This volume is used to bind your host path with the container.
      2. E.g. Setup docker in a container by routing all traffic to the host container.
    4. PersistenVolume and PersistentVolume Claim
      1. Support of external volume and mount this path
      2. PersistenVolume claim needs to be created and use that claim in a container to access that volume.
      3. StorageClass
        1. This is used for managing volumes dynamically.
  7. Configmap
    1. It supports storing configuration like app settings and secrets like passwords, certificates, etc.
    2. ConfigMap will be accessing in Pod using Environment variables or files in a volume.
    3. ConfigMap can be defined inside yaml file or access separate file and reference in yaml.
    4. Commands
      1. Create a ConfigMap using data from a config file: kubectl create configmap [cm name] --from-file=[path-to-file]
      2. Create ConfigMap from an env file: kubectl create configmap [cm name] --from-env-file=[path-to-file]
      3. Get a ConfigMap: kubectl get cm [cm name] o yaml
      4. Sample examples are here
  8. Secrets
    1. It supports secrets like passwords, certificates, etc.
    2. Go through Kubernetes docs for managing secrets best practices.
    3. Commands
      1. Create a secret and store it securely in Kubernetes: kubectl create secret generic my-secret --from-literal=pwd=my password
      2. Create a secret from a file: kubectl create secret generic my-secret --from-file=ssh-privatekey=~.ssh/id_rsa and --from-file=ssh.publickey=~ssh/id_rsa.pub
      3. Sample examples are here