I have a two projects Asp .net core Api and Asp .net core MVC.
In Api Project, this is my Deployment.yml code :
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapiservice2
namespace: default
labels:
app: product-app
spec:
replicas: 3
selector:
matchLabels:
service: webapi
template:
metadata:
labels:
app: product-app
service: webapi
spec:
containers:
- name: webapiservice2
image: ommkwn/webapiservice2:latest
ports:
- containerPort: 80
protocol: TCP
args:
- while true; do
echo sync app logs;
printenv POD_NAME POD_IP POD_SERVICE_ASCCOUNT;
sleep 20;
done;
env:
- name: ASPNETCORE_URLS
value: http://+:80
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_SERVICE_ASCCOUNT
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName
in this deployment.yml file this "ASPNETCORE_URLS" name value are printed successfully but the "POD_NAME", "POD_IP" , "POD_SERVICE_ASCCOUNT" are not printed when i run the Asp .net core MVC project
my Asp .net core MVC code :
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IConfiguration _configuration;
public HomeController(ILogger<HomeController> logger ,IConfiguration configuration)
{
_logger = logger;
_configuration = configuration;
}
[HttpGet]
public async Task<ActionResult> GetMySqlData()
{
var podName = _configuration["POD_NAME"];
var podIP = _configuration["POD_IP"];
var podServiceAccount = _configuration["POD_SERVICE_ASCCOUNT"];
var newurls = _configuration["ASPNETCORE_URLS"];
ViewBag.podName = podName;
ViewBag.podIp = podIP;
ViewBag.podServiceAccount = podServiceAccount;
ViewBag.newurls = newurls;
var Baseurl = "http://webapiservice2-0.default.svc.cluster.local:8081";
List<Customer> EmpInfo = new List<Customer>();
using (var client = new HttpClient())
{
//Passing service base url
client.BaseAddress = new Uri(Baseurl);
//Sending request to find web api REST service resource GetAllEmployees using HttpClient
HttpResponseMessage Res = await client.GetAsync("/home/mysqldata");
//Checking the response is successful or not which is sent using HttpClient
if (Res.IsSuccessStatusCode)
{
//Storing the response details recieved from web api
var EmpResponse = Res.Content.ReadAsStringAsync().Result;
//Deserializing the response recieved from web api and storing into the Employee list
EmpInfo = JsonConvert.DeserializeObject<List<Customer>>(EmpResponse);
}
//returning the employee list to view
return View(EmpInfo);
}
}
}
when i see with this command in kubernets "kubectl describe pod webapiservice2-f6d9d7bfb-4xvkv" there are all "POD_NAME" , "POD_IP", "POD_SERVICE_ASCCOUNT" and "ASPNETCORE_URLS" are get successfully.
like this:
So how to "POD_NAME" , "POD_IP", "POD_SERVICE_ASCCOUNT" are print on the MVC view
