Today I learned: How to make very small containers for golang binaries

The post Today I learned: How to make very small containers for golang binaries appeared first on Mirantis | Pure Play Open Cloud.
TL;DR – Official Go Docker container images tend to be beefy. The standard image on Docker Hub is called golang (docker pull golang), and tossing in a Go program (such as for interactive execution) will bring it up above 800MB. But building images from scratch (for example, using the scratch container) using compiled binaries that don’t need complex, multi-layered OS and language environment support, will keep things slimmer.
I’ve been building microservices applications for demos lately. A lot of the work has been in Node.js, because it’s easy. But this past weekend, I started learning Go (because ‘all the cool kids,’ obviously) and so, there I was, figuring out how to containerize Go programs.
It turns out this is easy, too. But I was surprised to discover how large the resulting container images were. Suppose we have a minimal program, hello.go, like:
package main

import (
“fmt”
“os”
)

func main() {
fmt.Println(os.Args)
}
… which prints the array containing its arguments. Running this on the command line with:
$ go run hello.go hi there
[/tmp/go-build289681080/b001/exe/hello hi there]
… gets you the standard argument array, beginning with the executable path.
Now you can put this into a golang container using the following Dockerfile…
FROM golang

COPY . .

CMD [“go”,”run”,”hello.go”,”hi”,”there”]
… then build it …
$ docker build -f Dockerfile.golang –tag hello:1.1 .
Sending build context to Docker daemon 2.073MB
Step 1/3 : FROM golang
—> 5fbd6463d24b
Step 2/3 : COPY . .
—> f72803dfaac0
Step 3/3 : CMD [“go”,”run”,”hello.go”,”hi”,”there”]
—> Running in 39e7765bec67
Removing intermediate container 39e7765bec67
—> f96c3d2c0861
Successfully built f96c3d2c0861
Successfully tagged hello:1.1
… and run it, and get the expected result:
$ docker run hello:1.1
[/tmp/go-build847833630/b001/exe/hello hi there]
But when you check with docker images, you see that the container is relatively yuge.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello 1.1 f96c3d2c0861 3 minutes ago 812MB
‘Kayso, you can make a much, much smaller container by changing your Dockerfile to this:
FROM scratch

COPY ./hello /go/bin/hello

CMD [“/go/bin/hello”,”hi”,”there”]
… and using the so-called ‘scratch’ image, which is basically an empty container without a shell.
But the scratch image also contains no Go language environment, so you need to compile your application into an executable first:
$ go build hello.go
… which gets you a hello binary in your local directory that you can execute like this …
$ ./hello hi there
[./hello hi there]
… and get back the (drum roll) expected result.
Looking back at the Dockerfile (called, in this case Dockerfile.scratch), you can see all it’s doing is copying the binary (hello) into a directory it creates in the container (/go/bin) and then running it from there. So build …
$ docker build -f Dockerfile.scratch –tag hello:1.2 .
Sending build context to Docker daemon 2.073MB
Step 1/3 : FROM scratch
—>
Step 2/3 : COPY ./hello /go/bin/hello
—> Using cache
—> fbc88299067f
Step 3/3 : CMD [“/go/bin/hello”,”hi”,”there”]
—> Running in dd925ee8a3ab
Removing intermediate container dd925ee8a3ab
—> 4a049a401c79
Successfully built 4a049a401c79
Successfully tagged hello:1.2

… and run …
$ docker run hello:1.2
[/go/bin/hello hi there]
… and (by this time, I figure you’re not surprised) … the expected result. But look at the container image:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello 1.2 4a049a401c79 33 seconds ago 2.07MB
That’s a pretty substantial size reduction!
Flipping from shell-based execution to no-shell-in-sight execution naturally comes with many potential gotchas. In this case, for example, if you were to build the arguments passed by your CMD out of expressions that required evaluation/expansion by a shell, things wouldn’t work as planned in a no-shell container. You’ll need to construct code carefully to run in such a stripped-back environment.
Now, be advised: I haven’t thought about side-effects, security, stability, gotchas that would no doubt be obvious to a seasoned Go dev, and I’d love to hear about them in the comments. But as we say in the artisanal code-creation atelier: “It works on my machine.” 
Today I Learned (TIL) is an intermittent journal of somewhat half-baked solutions to “speed bump” problems encountered by Mirantis Technical Marketing folks working well beyond our native spheres of expertise for research purposes. None of what we write about here has been checked by grown-ups, or is appropriate for production without further validation. Use at own risk. Comments, cautions, and suggestions for improvement are very welcome! Email jjainschigg@mirantis.com (Twitter: @jjainschigg).
The post Today I learned: How to make very small containers for golang binaries appeared first on Mirantis | Pure Play Open Cloud.
Quelle: Mirantis

Optimize your Azure costs to help meet your financial objectives

Many of our customers are facing difficult decisions about how to meet their funding needs for critical IT projects. We’re in this together to help you meet your financial objectives. Ensuring your Azure workloads are cost optimized can help free up funds to support essential surge areas like remote work.

For the fourth year running, cost optimization is the top cloud initiative according to Flexera’s 2020 State of the Cloud Report

Today, we’ll cover the Azure tools, offers, and guidance that can help you manage and optimize your cloud costs. You’ll learn how to understand and forecast your bill, cost optimize your workload, and control your spending. Then we’ll show you seven things you can do today to optimize your cloud costs and start saving.

Understand and forecast your costs

To manage and optimize your Azure costs, you first need to understand what you’re spending now and forecast what your bill is likely to be in the future for your current and planned projects.

Azure Cost Management + Billing gives you a full set of cloud cost management capabilities. You can use Cost Management + Billing to:

Monitor and analyze your Azure bill.
Set budgets and spending alerts.
Allocate costs to your teams and projects.

As you embark on new priority workloads or revisit existing workloads for cost optimization opportunities, you’ll want to estimate the costs involved. Cost Management + Billing surfaces rich operational and financial insights, including cost forecasts. In addition, the Azure pricing calculator and Total Cost of Ownership (TCO) calculator can help you estimate costs for your next Azure projects.

 

Cost optimize your workloads

Once you have a better understanding of your spending now and in the future, you can focus on cost optimizing your Azure resources and workloads. In this area, Azure Advisor and the Microsoft Azure Well-Architected Framework are our primary optimization tools, while key Azure offers and licensing terms, like the Azure Hybrid Benefit and Azure Reservations can help you realize significant savings.

Azure Advisor helps you cost optimize your Azure resources with personalized best practice recommendations based on your configurations and usage data. For example, Azure Advisor can help you identify unused resources like idle virtual machines (VMs) and find opportunities to right-size resources like SQL databases.

The Azure Well-Architected Framework provides guidance and best practices at a broader architectural level to help you cost optimize your workloads. You can also take the Azure Well-Architected Review to assess your current or planned workloads from a cost perspective to get tailored recommendations on how to improve.

In addition, Azure offers and licensing terms can make a big difference when it comes to cost savings including:

Azure Hybrid Benefit: AWS is five times more expensive than Azure for Windows Server and SQL Server. Save when you migrate your on-premises workloads to Azure.
Azure Reservations: Get a discount of up to 72 percent over pay-as-you-go pricing on Azure services when you prepay for a one- or three-year term with reservation pricing.
Azure Spot Virtual Machines: Utilize unused Azure compute capacity at deep discounts—up to 90 percent compared to pay-as-you-go prices.
Azure Dev/Test Pricing: Take advantage of significant rate discounts for your ongoing development and testing—and avoid paying Microsoft software charges on your VMs.

Control your costs

Finally, you’ll want to put in place organization-wide cost management policies and guardrails, so you can free up your teams to go fast while keeping your costs under control.

For many customers, governing cost is a major concern when it comes to the cloud. Balancing workload requirements like performance demands and reliability needs with cloud costs can be challenging, especially during times of business transformation like we see today. The Microsoft Cloud Adoption Framework for Azure provides organizational cost management guidance as part of a cloud governance strategy. This guidance can help mitigate cloud spending risks through cost management best practices.

Once you’ve set your organizational policies for cost management, you can implement these cost controls and guardrails directly in your Azure environment with Azure Policy to achieve real-time cloud compliance at scale.

7 ways to optimize your Azure costs today

With many tools to use, offers to take advantage of, and best practices to follow, you may wonder how to get started. To help you get going fast, we recommend starting with these seven ways you can optimize your Azure costs today.

Shut down unused resources: Identify idle virtual machines, ExpressRoute circuits, and other resources with Azure Advisor. Get recommendations on which resources to shut down and see how much you would save.
Right-size underused resources: Find underutilized resources with Azure Advisor and get recommendations on how to reduce spending by reconfiguring or consolidating them.
Reserve instances for consistent workloads: Save money when you reserve resources in advance. Plus, enjoy monthly payment options at no extra cost.
Take advantage of the Azure Hybrid Benefit: Realize major savings when you bring your Windows Server and SQL Server on-premises licenses with Software Assurance to Azure.
Get Azure Dev/Test pricing for development environments: Get rate discounts on Azure to support development and testing scenarios.
Set up budgets and allocate costs to teams and projects: Create and manage budgets for the Azure services you use or subscribe to—and monitor your organization’s cloud spending—with Azure Cost Management.
Explore serverless technologies and new architectures: Optimize your workloads with guidance for building apps and solutions on Azure using best practices and proven patterns.

Get started with cost optimization

Cloud cost optimization has never been more critical than it is today. Azure is here to support you with tools, offers, and best practices to help you optimize your cloud costs and meet your technical and business goals during this difficult time.

We’re also kicking off a new blog series to help you optimize your Azure environment. Check the Azure blog soon for the latest cost optimization guidance and best practices or visit our cost optimization on Azure page to learn more.
Quelle: Azure

Seven ways to achieve cost savings and deliver efficiencies with Azure infrastructure

The global health crisis has transformed the way we work and live. At Microsoft, we are committed to doing what we can to help our customers respond to the crisis and plan ahead for future success.

In the past couple of months, I have been learning from—and inspired by—IT leaders around the globe who have been quickly adjusting IT priorities to enable remote work, and optimize costs and efficiencies while investing in smart ways to prepare for recovery and future growth. To achieve these goals, many IT leaders are accelerating the adoption of cloud computing.

Achieve cost savings and deliver efficiencies with Azure infrastructure

Below are seven ways in which Azure infrastructure can help you today to improve cash flow, achieve cost savings, increase operational efficiencies, and unify security and management.

1. Enable remote work anywhere and ensure productivity

To ensure that users have access to desktops and apps they need to work from anywhere, you can spin up and scale virtual desktops quickly with Windows Virtual Desktop—no need to provision new hardware. Windows Virtual Desktop delivers the best Windows 10 and Office 365 virtual desktop experience with support for multi-session. You only pay for the infrastructure that you use and save money by turning off machines when they are not in use. Read the blog to learn about new Windows Virtual Desktop capabilities we recently released to enable even faster deployment, further enhance security and compliance, and provide the Microsoft Teams user experience you would expect on a desktop from within your virtual desktop.

In addition to virtual desktops, employees need access to resources across on-premises and cloud. With Azure, you can quickly extend and expand your on-premises virtual private network (VPN) solution with Azure VPN Gateway. It can be provisioned quickly and scale up and down easily. The Azure network is designed to withstand sudden changes in resource utilization and can easily manage peak utilization periods. Read the blog to learn about best practices and tips on how Azure VPN helps organizations scale remote work.

2. Maintain business continuity to avoid costly disruptions

Many companies are taking a closer look at their backup and disaster recovery strategy to make sure data and applications are fully protected from business disruptions. With just a few clicks, Azure Backup and Azure Site Recovery let customers easily back up their data and applications to the cloud, and quickly deploy cloud-based replication, failover, and recovery processes.

Also, to ensure reliable connectivity, customers are using Azure Virtual WAN with supported partner SD-WAN devices to connect remote branch offices to on-premises and public cloud where applications and data are hosted. Azure Virtual WAN routes traffic from the closest network location to the branch office over Microsoft’s dedicated global network to its destination, providing fast and reliable connectivity at scale.

3. Secure on-premises and cloud workloads from increased cyberattacks

With the increased dependence on digital infrastructure to enable remote work, there has been an increase in cybercrime. Microsoft invests more than $1 billion USD every year on cybersecurity and has a massive threat intelligence source processing more than eight trillion signals a day.

Azure Security Center provides a unified view of the security state of all your cloud and on-premises workloads and gives you security recommendations including turning on multi-factor authentication (MFA), ensuring secure shell (SSH) and remote desktop protocol (RDP) ports are protected, and more. Azure Web Application Firewall and Azure DDoS Protection protect your web workloads with zero trust security including verifying identity on every access and ensuring your networks are correctly segmented. Many customers are also taking advantage of Azure Sentinel, a cloud native security information and event management SIEM, to access advanced AI-enabled threat protection. Learn more about strengthening security operations and open-sourcing new threat intelligence during Covid-19.

4. Efficiently govern and manage your hybrid environments

Customers’ IT environments are evolving with different types of applications often running on a diverse set of hardware across distributed locations. How to efficiently manage IT resources without slowing down developer innovation is a key challenge that IT leaders face today. Azure Arc lets customers seamlessly govern, manage, and secure Windows and Linux servers, Kubernetes clusters and applications across on-premises, multicloud, and the edge from a single control plane. Azure Arc also brings Azure services such as Azure data services to any infrastructure, so customers can take advantage of Azure innovation—including the latest cloud capabilities, scalability, rapid deployment, and cloud billing—on any cloud and any Kubernetes cluster.

5. Migrate to the cloud and save money

Organizations are accelerating cloud migration to reduce capital expenditure, realize cost savings and speed up time to value. With offers including Azure Hybrid Benefit and free extended security updates, Azure is five times cheaper than AWS to migrate Windows Server and SQL Server workloads. Migrate your Linux workloads to Azure to gain more performance and efficiency on your favorite distributions with integrated support from Microsoft. In addition, we help customers reduce migration costs and accelerate their migration journey with free migration tools, guidance, and best practices through the Azure Migration Program.

6. Modernize on-premises infrastructure

Many customers keep certain workloads on-premises to meet regulatory requirements, address latency issues, or maximize existing investments. In this case, customers can take advantage of cloud innovation by modernizing their on-premises infrastructure and increase efficiency.

For example, Azure Stack HCI lets customers consolidate on-premises virtualized applications on cloud-connected, hyper-converged infrastructure to access the best price-performance for storage and compute. Azure Stack Hub helps customers in over 60 countries build and deploy cloud-native applications on-premises and run their own private, autonomous cloud—connected or disconnected—from Azure.

7. Continuously cost optimize your workloads

Azure offers many ways for customers to optimize their costs. Azure Cost Management + Billing give customers free tools to monitor and analyze cloud spend, set budget and spending alerts, and allocate cloud costs across teams. Azure Advisor helps organizations optimize cloud resource utilization with personalized recommendations. Offers such as Azure Spot Virtual Machine combined with Azure Reservations let customers save up to 90 percent over pay-as-you-go pricing on Azure services with pre-paid reservation pricing or utilizing unused Azure compute capacity at deep discounts. Learn more about all the ways to optimize your Azure costs.

Get started with Azure infrastructure services today

We are publishing more blog posts in the coming weeks to go deeper on some of the topics covered above. Be sure to come back to the Azure blog and check out our new post. Also visit Azure infrastructure as a service (IaaS) to learn more about how Azure infrastructure services and solutions can help you.
Quelle: Azure