kubectl run mypod --image=nginx --dry-run -o yaml kubectl run mypod --image=nginx --namespace=default --env=HELLO=VALUE --dry-run -o yaml
- Run a container interactively
docker run -it -p 8080:80 -e ENV_VAR=value -e ENV_VAR_SECRET=value alpine sh
docker run -it -p 8080:80 nginx
- Run a container non-interactively
docker run -d -p 8080:80 -e ENV_VAR=value -e ENV_VAR_SECRET=value alpine sh -c "sleep 1000"
docker run --name container --user 1000 -d -p 8080:80 -e ENV_VAR=value -e ENV_VAR_SECRET=value alpine sh -c "sleep 1000"
- Open a shell into a running container docker exec -it container sh
$registry_uri="dockerhubregistry/myrepo"
docker build --tag $registry_uri .
docker run --rm –it $registry_uri sh
docker login -u dockerhubregistry
docker push $REPO
registry_uri="dockerhubregistry/myrepo"
docker build --tag $registry_uri .
docker run --rm –it $registry_uri sh
docker login -u dockerhubregistry
docker push $registry_uri
$registry="akstraining123"
$registry_uri="akstraining123.azurecr.io"
$accounts=az account list
if ($accounts.length -eq 0){
az login --tenant gunnebo.com
}
az acr login --name $registry
docker build -t $registry_uri/my/repo:0.13 --tag $registry_uri/my/repo:latest .
docker push $registry_uri/my/repo:0.13
docker push $registry_uri/my/repo:latest
registry="akstraining123"
registry_uri="akstraining123.azurecr.io"
accounts=$(az account list)
if $accounts; then
az login --tenant gunnebo.com
fi
az acr login --name $registry
docker build -t $registry_uri/my/repo:0.13 --tag $registry_uri/my/repo:latest .
docker push $registry_uri/my/repo:0.13
docker push $registry_uri/my/repo:latest
kubectl run mypod --rm -it --port 80 --env="ENV_VAR_SECRET=value" --image=nginx
--rm remove container once PID 1 it had exit'ed
--port 80 expose port 80 outside of the container
-it Run interactively
kubectl port-forward mypod 8080:80
- Now go to http://127.0.0.1:8080/
Pod -> Deployment/Job/DaemonSet/Statefulset -> ReplicaSets
kubectl apply -f pod.yaml
kubectl apply -f Deployment.yaml
kubectl apply -f DeploymentRollingUpdate.yaml
kubectl apply -f PodService.yaml
- Apply an immediate change to the deployment to upgrade it
kubectl set image deployment.v1.apps/mydep alpine:3.9.3
- Check status of the upgrade
kubectl rollout status deployment.v1.apps/mydep
- Check the history of rollouts
kubectl rollout history deployment.v1.apps/mydep --revision=2
- Rollback
kubectl rollout undo deployment.v1.apps/mydep
- Create the chart
cd charts helm create mynewchart rm -fr mynewchart/templates/tests
- Install the chart
helm upgrade mypod ./mynewchart --install --namespace default
- Run the port-forward command displayed in the prompt
#Perfrom and record the RollingUpgrade of a Kubernetes deployment to docker image version nginx:1.161 where the deployment name is ‘nginx-deployment’ and the container name is ‘nginx’
kubectl --record deployment.apps/nginx-deployment set image deployment.v1.apps/nginx-deployment nginx=nginx:1.16.1
--record You can specify the --record flag to write the command executed in the resource annotation kubernetes.io/change-cause. The recorded change is useful for future introspection. For example, to see the commands executed in each Deployment revision. See here for more information
#Generate a yaml file for a deployment
kubectl create deployment mydeployment --image=nginx --dry-run -o yaml
#MacOS/Linux - Output a list of Kubernetes Resource “Kind:” vs “apiVersion:” for use at the top of all Kubernetes yaml files
for kind in `kubectl api-resources | tail +2 | awk '{ print $1 }'`; do kubectl explain $kind; done | grep -e "KIND:" -e "VERSION:"
az ad sp create-for-rbac --skip-assignment --name myAKSClusterServicePrincipal
- Populate the below file with the provided
appId
andpassword
session2/terraform/terraform.tfvars
- MacOS
registry_uri="akstraining123.azurecr.io"
accounts=$(az account list)
if $accounts; then
az login --tenant gunnebo.com
fi
az acr login --name $registry_uri
docker build -t $registry_uri/terraform:0.14.6 --tag $registry_uri/terraform:latest .
docker push $registry_uri/terraform:0.14.6
docker push $registry_uri/terraform:latest
- Windows
$registry="akstraining123"
$registry_uri="akstraining123.azurecr.io"
$accounts=az account list
if ($accounts.length -eq 0){
az login --tenant gunnebo.com
}
az acr login --name $registry_uri
docker build -t $registry_uri/terraform:0.14.6 --tag $registry_uri/terraform:latest .
docker push $registry_uri/terraform:0.14.6
docker push $registry_uri/terraform:latest
cd session2/terraform ;
# Login to ACR
registry_uri="akstraining123.azurecr.io"
accounts=$(az account list)
if $accounts; then
az login --tenant gunnebo.com
fi
az acr login --name $registry_uri
# Run the new
docker rmi akstraining123.azurecr.io/terraform:0.14.6
docker run --rm -it -v ~/.azure:/root/.azure -v `pwd`:/project akstraining123.azurecr.io/terraform:0.14.6 bash
cd /project
# Ensure Azure Account is set
az account set --subscription 64e455b9-c577-484c-8710-35cb4a94a2c7
# Initialise the Terraform backend state
terraform init
# Deploy resources using Terraform
terraform apply
cd session2/terraform ;
$pwd=Get-Location
# Run the new
docker rmi akstraining123.azurecr.io/terraform:0.14.6
docker run --rm -it -v ~/.azure:/root/.azure -v ${pwd}:/project akstraining123.azurecr.io/terraform:0.14.6 bash
cd /project
# Ensure Azure Account is set
az account set --subscription 64e455b9-c577-484c-8710-35cb4a94a2c7
# Initialise the Terraform backend state
terraform init
# Deploy resources using Terraform
terraform apply
- Update the AKS tags to include your name eg. "georgec" : "true",
Edit:
session2/terraform/aks-cluster.tf
- Deploy the change (Mac)
cd session2/terraform ;
# Run the new
docker run --rm -it -v ~/.azure:/root/.azure -v `pwd`:/project akstraining123.azurecr.io/terraform:0.14.6 bash
cd /project
# Initialise the Terraform backend state
terraform init
# Deploy resources using Terraform
terraform apply
- Deploy the change (Win)
cd session2/terraform ;
# Run the new
$pwd=Get-Location
docker run --rm -it -v ~/.azure:/root/.azure -v ${pwd}:/project akstraining123.azurecr.io/terraform:0.14.6 bash
cd /project
# Initialise the Terraform backend state
terraform init
# Deploy resources using Terraform
terraform apply
Either
- Retrieve the Kubernetes configuration to authenticate your local Kubectl
or
- Use Azure CLI to retrieve the configuration
- Retrieve the Kubernetes configuration to authenticate your local Kubectl
terraform apply
# or just use the output function
terraform output
-
Copy and paste it to ~/.kube/kubeconfig_aks-training
-
Use the context
export KUBECONFIG=~/.kube/kubeconfig_aks-training
- Test connectivity
kubectl get pods
- Deploy a container
kubectl apply -f pod.yaml
- Use Azure CLI to retrieve the configuration
- Retrieve kube config using Azure CLI
az aks get-credentials --resource-group aks-training --name smashing-tortoise-aks
- Test connectivity
kubectl get pods
- Deploy a container
kubectl apply -f pod.yaml
-
See .bash_profile
-
Deploy Metrics server
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.4.2/components.yaml Kubectl top nodes Kubectl top pod
- Deploy K8s Dashboard
# Install the dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
# Run the local k8s proxy
kubectl proxy --port=8001 --address=0.0.0.0 --accept-hosts='.*'
# Browse to the service
http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#!/login
kubectl -n kube-system describe secret deployment-controller-token-frsqj
# To login using the token (MacOS)
kubectl -n kube-system get secret deployment-controller-token-bq2q6 -o jsonpath='{.data.token}' | base64 --decode
# To login using the token (Windows)
$token=kubectl -n kube-system get secret deployment-controller-token-bq2q6 -o jsonpath='{.data.token}'
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($token))