Cant access kubernetes pod (minikube) - wordpress

On the image, you can see the service and the pod.
If I execute "curl localhost" inside the container, I get a response, but I am not able to access it from outside.
What is wrong?
This is the file I run "kubectl -f on:
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "wordpress-site",
"labels": {
"app": "web"
}
},
"spec": {
"containers": [
{
"name": "wordpress",
"image": "wp:latest",
"imagePullPolicy": "Never",
"ports": [
{
"containerPort": 80
}
]
}
]
}
}

First I would need some more information but with what you gave me I will make the assumption you want to access it from outside the node the pod is. For this problem we can use kubernetes services.
You could easy add the service configuration to the yaml file, here is the api reference for doing that: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#-strong-service-apis-strong-

Got it working by setting:
hostNetwork: true

Related

Passing config file from one container to another in ecs ec2 launch type

I have been struggling with this issue for a while: I want to pass the config file located on Container A app/config-file/nginx/nginx.conf and pass it into etc/nginx/conf.d/default.conf so that the official nginx image that I'm running along side my default container can use my custom config file. I have tried to use bindMounts as shown in the aws docs to do this and even set a start-up dependency but for some reason, I am still not getting the correct config file to populate. It just resorts to the default config that comes with the nginx image. Below is my task definition template showing how I am trying to do this (I created named volumes outside of the task-definition)
{
"command": [],
"entrypoint": [
"uwsgi",
"--ini",
],
"cpu": 250,
"memoryReservation": 1024,
"image": "${image_url}",
"name": "${container_name}",
"mountPoints": [
{
"containerPath": "/app/config-file/nginx",
"sourceVolume": "nginx-config"
}
],
},
{
"name": "${container_name}-nginx",
"image": "nginx:1.19-alpine",
"essential": true,
"dependsOn": [
{
"containerName": "${container_name}",
"condition": "START"
}
],
"mountPoints": [
{
"containerPath": "/etc/nginx/conf.d/",
"sourceVolume": "nginx-config"
}
],
"cpu": 250,
"memoryReservation": 250,
"portMappings": [
{
"protocol": "tcp",
"containerPort": 4000,
"HostPort" : 0
}
]
}
]```
I do want to mention that I know there are ways to do this by using efs, s3, or by baking the custom config into the nginx image. I would prefer if I did not have to go down those routes though.

Getting "parent resource not found" during ARM template deployment

I have private DNS zone zone.private which is already deployed in resource group and I'm trying to add A record to it with ARM template below which fails with Status Message: Can not perform requested operation on nested resource. Parent resource 'zone.private' not found. (Code:ParentResourceNotFound)
I'm supposed to be able to refer to refer to resources deployed in the same resource group to deploy nested resources but it fails for whatever reason. I have another zone called zone.domain.com deployed to the same resource group and deploying to that succeeds with no issues.
{
"type": "Microsoft.Network/dnsZones/A",
"apiVersion": "2018-05-01",
"name": "[concat('zone.private', '/', 'webexport-lb')]",
"properties": {
"TTL": 3600,
"ARecords": [
{
"ipv4Address": "1.1.1.1"
}
]
}
},
If you have a private DNS zone, you could use Microsoft.Network/privateDnsZones/A instead of Microsoft.Network/dnsZones/A.
So change it like this:
{
"type": "Microsoft.Network/privateDnsZones/A",
"apiVersion": "2018-09-01",
"name": "[concat('zone.private', '/', 'webexport-lb')]",
"properties": {
"ttl": 3600,
"aRecords": [
{
"ipv4Address": "1.1.1.1"
}
]
}
}

Wildcard path proxy to Google Cloud Run

I have two cloud run services (Next.js and API server) and I want to serve them through a single endpoint.
I want requests to /api to be forwarded to API service and all other other requests (/*) to be forwarded to Next.js server.
Cloud Run documentation suggests that I use Endpoint but it does not seem to support wildcard paths.
What are the possible alternatives?
Google API Gateway supports different wildcards, I'using Google Functions as backend, but that shouldn't make a different when using the GW with Google Run.
My scenario:
/ should route to the /index.html
/assets should route to the /assets/any-file-here.png
/logo-256.png should route to the /logo-256.png
/endpoint-1 should route only to the API, but hosted on another function
/endpoint-2/some-param should route only to the API, hosted on the same function as the assets
With this configuration everything get's routed liked wanted, using Double Wildcard Matching.
It doesn't matter that the wildcard is before specific routes, this is handled correctly by the gateway.
{
"swagger": "2.0",
"info": {
"version": "0.0.1",
"title": "Some API w/ Assets"
},
"paths": {
"/": {
"get": {
"summary": "home",
"operationId": "home",
"parameters": [],
"x-google-backend": {
"address": "https://THE-GOOGLE-RUN-OR-FUNCTION",
"path_translation": "CONSTANT_ADDRESS"
},
"responses": {
"200": {
"description": "Home"
}
}
}
},
"/{files=**}": {
"get": {
"summary": "assets",
"operationId": "assets",
"parameters": [
{
"in": "path",
"name": "files",
"type": "string",
"required": true
}
],
"x-google-backend": {
"address": "https://THE-GOOGLE-RUN-OR-FUNCTION",
"path_translation": "APPEND_PATH_TO_ADDRESS"
},
"responses": {
"200": {
"description": "assets"
}
}
}
},
"/endpoint-1": {
"get": {
"summary": "Some pure backend api",
"operationId": "ep1",
"x-google-backend": {
"address": "https://SOME-OTHER-GOOGLE-RUN-OR-FUNCTION",
"path_translation": "APPEND_PATH_TO_ADDRESS"
},
"parameters": [],
"responses": {
"200": {
"description": "result values"
}
}
}
},
"/endpoint-2/{some_param}": {
"get": {
"summary": "Some pure backend API with path param",
"operationId": "ep2",
"parameters": [
{
"in": "path",
"name": "some_param",
"type": "string",
"required": true
}
],
"x-google-backend": {
"address": "https://THE-GOOGLE-RUN-OR-FUNCTION",
"path_translation": "APPEND_PATH_TO_ADDRESS"
},
"responses": {
"200": {
"description": "result values"
}
}
}
}
}
}
But with this setup, your page won't be that fast, I recommend adding Google Load Balancer with Google CDN before your API gateway when you are serving files.
This is best addressed through the usage of Firebase hosting since they have a tutorial to do just this.
Hope you find this useful

Azure Resource Manager set static IP using json template

Using Azure Resource Manager Json template, can we set internal static IP without having to assign IP? My template creates a couple of Vms. When I set privateIPAllocationMethod to Static I get error that I have to set the IP also. Is it possible to assign IP dynamically and set it static?
Or are you looking for something you can do in ARM after you get an IP from Azure using dynamic the switch to static.
{
"name": "SetStaticIP",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2015-01-01",
"dependsOn": [
"[concat(parameters('envPrefix'),parameters('vmName'),'nic')]",
"[concat(parameters('envPrefix'),parameters('vmName'))]",
"Microsoft.Insights.VMDiagnosticsSettings"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/SetStaticIP.json', parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"VirtualNetwork": {
"value": "[parameters('VirtualNetwork')]"
},
"VirtualNetworkId": {
"value": "[parameters('VirtualNetworkId')]" },
"nicName": {
"value": "[concat(parameters('envPrefix'),parameters('vmName'),'nic')]"
},
"ipAddress": {
"value": "[reference(concat(parameters('envPrefix'),parameters('vmName'),'nic')).ipConfigurations[0].properties.privateIPAddress]"
}
}
}
}
YES you can change dynamically assigned IP to static. Try this-
$nic=Get-AzureRmNetworkInterface -Name "TestNIC" -ResourceGroupName "TestRG"
$nic.IpConfigurations[0].PrivateIpAllocationMethod = "Static"
$nic.IpConfigurations[0].PrivateIpAddress = "x.x.x.x"
Set-AzureRmNetworkInterface -NetworkInterface $nic
You can refer to this article- https://azure.microsoft.com/en-us/documentation/articles/virtual-networks-static-private-ip-arm-ps/
Thanks.

Azure Resource Manager - Multiple VM NAT Rules

I am trying to create an ARM template that will provision multiple webservers with directly accessible ports. For instance I want a VM to have either port 9001 or 9002 open based on what the index of the VM is.
I am struggling to get the frontendPort parameter to accept a function. Here is the documentation that I have used.
Here is what the relevant portion of my template looks like:
"inboundNatRules": [
{
"copy": {
"name": "natCopy",
"count": "[parameters('numberOfVms')]"
},
"name": "[concat('directHttps-', copyIndex())]",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(variables('lbID'),'/frontendIPConfigurations/LoadBalancerFrontEnd')]"
},
"frontendPort": "[add(9001, copyIndex())]",
"backendPort": 9001,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 4,
"protocol": "Tcp",
"backendIPConfiguration": {
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('vmNicName'), copyIndex()), 'ipconfig')]"
}
}
}
]
I was hoping that the this particular port would result in either "9001", or "9002".
"frontendPort": "[add(9001, copyIndex())]"
Instead, I see an error in Visual Studio's Intellisense, and when I try to deploy the solution.
Create template deployment 'deploymenttemplate-0107-1555'.
New-AzureRmResourceGroupDeployment : Resource Microsoft.Network/loadBalancers 'webserverLb'
failed with message 'Unable to process template language expressions for resource
'/subscriptions/some random guid/resourceGroups/webservers/providers/Microsoft.Network/loadBalancers/webserverLb'
at line '102' and column '10'. 'The template function 'copyIndex' is not expected at this location.
The function can only be used in a resource with copy specified.
Long story short, I'm simply trying to have the same number of NAT rules as I have VM's in the template, and dynamically assign the external port number.
Please let me know if I can provide any more information. Thank you.
Try:
[Concat(900,CopyIndex(1))]
which will offset the index (0 based) and give you the number you want.
This is the syntax that works for copying the NAT rules (I am adding an RDP rule on the standard back-end port):
"copy": [
{
"name": "inboundNatRules",
"count": "[parameters('numberOfWebInstances')]",
"input": {
"name": "[concat(parameters('lbNatRulePrefix'), copyindex('inboundNatRules'))]",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('lbFrontEndIpId')]"
},
"frontendPort": "[add(50001, copyIndex('inboundNatRules'))]",
"backendPort": 3389,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 4,
"protocol": "tcp"
}
}
}
],
And then to apply the rules to the NIC, you actually need to add some code on the NIC itself. The following is for both LB rules and NAT rules:
"loadBalancerBackendAddressPools": [
{
"id": "[concat(variables('lbID'), '/backendAddressPools/', parameters('lbPoolName'))]"
}
],
"loadBalancerInboundNatRules": [
{
"id": "[concat(variables('lbID'),'/inboundNatRules/' , parameters('lbNatRulePrefix'), copyindex())]"
}
]
#Your script is wrong it should you are writing copyindex() but you need to pass the name of rule it should work.
"inboundNatRules": [
{
"copy": {
"name": "natCopy",
"count": "[parameters('numberOfVms')]"
},
"name": "[concat('directHttps-', copyIndex(natCopy,1))]",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(variables('lbID'),'/frontendIPConfigurations/LoadBalancerFrontEnd')]"
},
"frontendPort": "[add(9001, copyIndex(natCopy,1))]",
"backendPort": 9001,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 4,
"protocol": "Tcp",
"backendIPConfiguration": {
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('vmNicName'), copyIndex(natCopy,1)), 'ipconfig')]"
}
}
}
$LoadBalancer = Get-AzureRmLoadBalancer -ResourceGroupName $ResourceGroupName -Name $LoadBalancerName
$publicIP1 = Get-AzureRmPublicIpAddress -name $pipName -resourcegroupname $ResourceGroupName
$frontendIP1 = Get-AzureRmLoadBalancerFrontendIpConfig -LoadBalancer $LoadBalancer -Name $FrontendIpConfigName
$LoadBalancer | Add-AzureRmLoadBalancerInboundNatRuleConfig -Name "nat_rule_tcp_IP1_49157" -FrontendIpConfiguration $frontendIP1 -IdleTimeoutInMinutes 4 -Protocol TCP -FrontendPort 49157 -BackendPort 49157 | Set-AzureRmLoadBalancer

Resources