Wednesday, June 21, 2017

Creating the Kuberenetes cluster on Azure and running dotnet core containers

Install the azure cli 2.0 and run the following commands in prowershell

az login  # login to azure

az group create --name="LinuxACSResource" --location="Southeast Asia" # Create a resource group

az acs create --orchestrator-type=kubernetes --resource-group "LinuxACSResource" --name="cluster
name" --dns-prefix="dnsprefix" --generate-ssh-keys # Create a Kubernetes cluster

az acs kubernetes install-cli # Install kube ctl

az acs kubernetes get-credentials --resource-group="LinuxACSResource" --name="clustername"
#  Get the kubernetes config file

PS C:\Program Files (x86)> .\kubectl.exe get nodes #  Get the kubernetes nodes

PS C:\Program Files (x86)> .\kubectl.exe run nginx --image nginx #  Run the Nginx image

PS C:\Program Files (x86)> .\kubectl.exe get pods #  Get the Pods

PS C:\Program Files (x86)> .\kubectl.exe expose deployments nginx --port=80 --type=LoadBalancer #  Run a service

PS C:\Program Files (x86)> .\kubectl.exe get svc #  Get a service

Run the dotnet core container

docker login

docker login acrgirish.azurecr.io -u ACRgirish -p K7/n0/8r9zt9AIg+JCftoC6Dyzrg=4rf

docker tag corewebapp:dev acrgirish.azurecr.io/app

docker push acrgirish.azurecr.io/app

PS C:\Program Files (x86)> .\kubectl.exe create -f C:\Users\aditi\Desktop\K8\Deployment.yaml

PS C:\Program Files (x86)> .\kubectl.exe get pods

PS C:\Program Files (x86)> .\kubectl.exe create -f C:\Users\aditi\Desktop\K8\Service.yaml


//dockerfile

FROM microsoft/aspnetcore:1.1
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-/bin/Release/netcoreapp1.1/publish} .
ENTRYPOINT ["dotnet", "corewebapp.dll"]


//deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: dotnetcoreapp
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: dotnetcoreapp
    spec:
      containers:
      - name: coreapp
        image: acrgirish.azurecr.io/app
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: myregistrykey


//service.yaml

apiVersion: v1
kind: Service
metadata:
   namedotnetcoreapp
spec:
  selector:
    appdotnetcoreapp
  typeLoadBalancer
  ports:
    - port: 80

kubectl create secret docker-registry myregistrykey --docker-server=https://myregistry.azurecr.io --docker-username=ACR_USERNAME --docker-password=ACR_PASSWORD --docker-email=ANY_EMAIL_ADDRESS

No comments:

Post a Comment